diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 82394f6e..e5553216 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -1524,6 +1524,9 @@ nd6_new_onlink_prefix(ip6_addr_t *prefix, struct netif *netif) s8_t nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif) { +#ifdef LWIP_HOOK_ND6_GET_GW + const ip6_addr_t *next_hop_addr; +#endif /* LWIP_HOOK_ND6_GET_GW */ s8_t i; #if LWIP_NETIF_HWADDRHINT @@ -1567,6 +1570,12 @@ nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif) /* Destination in local link. */ destination_cache[nd6_cached_destination_index].pmtu = netif->mtu; ip6_addr_copy(destination_cache[nd6_cached_destination_index].next_hop_addr, destination_cache[nd6_cached_destination_index].destination_addr); +#ifdef LWIP_HOOK_ND6_GET_GW + } else if ((next_hop_addr = LWIP_HOOK_ND6_GET_GW(netif, ip6addr)) != NULL) { + /* Next hop for destination provided by hook function. */ + destination_cache[nd6_cached_destination_index].pmtu = netif->mtu; + ip6_addr_set(&destination_cache[nd6_cached_destination_index].next_hop_addr, next_hop_addr); +#endif /* LWIP_HOOK_ND6_GET_GW */ } else { /* We need to select a router. */ i = nd6_select_router(ip6addr, netif); diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 304609be..336b77e9 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2469,6 +2469,22 @@ #define LWIP_HOOK_IP6_ROUTE(src, dest) #endif +/** + * LWIP_HOOK_ND6_GET_GW(netif, dest): + * - called from nd6_get_next_hop_entry() (IPv6) + * - netif: the netif used for sending + * - dest: the destination IPv6 address + * Returns the IPv6 address of the next hop to handle the specified destination + * IPv6 address. If NULL is returned, a NDP-discovered router is used instead. + * The returned address MUST be reachable on the specified netif! + * This function is meant to implement advanced IPv6 routing together with + * LWIP_HOOK_IP6_ROUTE(). The actual routing/gateway table implementation is + * not part of lwIP but can e.g. be hidden in the netif's state argument. +*/ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_ND6_GET_GW(netif, dest) +#endif + /** * LWIP_HOOK_VLAN_CHECK(netif, eth_hdr, vlan_hdr): * - called from ethernet_input() if VLAN support is enabled