From 6b9264b49e3e29d5bd610bc9122576ddffba3388 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 24 Mar 2019 21:34:08 +0100 Subject: [PATCH] Fix bug #55972: The Neighbour Solicitation used to do IPv6 address resolution was wrong Apply patch from Gao Qingshui --- src/core/ipv6/nd6.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 039b7963..80287065 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -1187,10 +1187,22 @@ nd6_send_ns(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags) LWIP_ASSERT("target address is required", target_addr != NULL); - if (!(flags & ND6_SEND_FLAG_ANY_SRC) && - ip6_addr_isvalid(netif_ip6_addr_state(netif,0))) { - /* Use link-local address as source address. */ - src_addr = netif_ip6_addr(netif, 0); + if (!(flags & ND6_SEND_FLAG_ANY_SRC)) { + int i; + for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && + ip6_addr_netcmp(target_addr, netif_ip6_addr(netif, i))) { + src_addr = netif_ip6_addr(netif, i); + break; + } + } + + if (i == LWIP_IPV6_NUM_ADDRESSES) { + LWIP_DEBUGF(IP6_DEBUG | LWIP_DBG_LEVEL_WARNING, ("ICMPv6 NS: no available src address\n")); + ND6_STATS_INC(nd6.err); + return; + } + /* calculate option length (in 8-byte-blocks) */ lladdr_opt_len = ((netif->hwaddr_len + 2) + 7) >> 3; } else {