net: if: Prefer always preferred IPv6 address

Always prefer preferred IPv6 address over deprecated one
regardless of prefix length. This works now same way as in
Linux.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2025-05-15 14:33:02 +03:00 committed by Benjamin Cabé
commit da13b5184c

View file

@ -3173,7 +3173,26 @@ static struct in6_addr *net_if_ipv6_get_best_match(struct net_if *iface,
len = prefix_len;
}
if (len >= *best_so_far) {
if (ipv6->unicast[i].addr_state == NET_ADDR_DEPRECATED &&
addr_state == NET_ADDR_PREFERRED) {
/* We have a preferred address and a deprecated
* address. We prefer always the preferred address
* over the deprecated address.
* See RFC 6724 chapter 5.
*/
NET_DBG("skipping deprecated address %s",
net_sprint_ipv6_addr(&ipv6->unicast[i].address.in6_addr));
continue;
}
if (len >= *best_so_far ||
(ipv6->unicast[i].addr_state == NET_ADDR_PREFERRED &&
addr_state == NET_ADDR_DEPRECATED)) {
/* Currently we have best deprecated address, but
* should now choose the preferred address regardless
* of the length.
*/
/* Mesh local address can only be selected for the same
* subnet.
*/
@ -3182,17 +3201,6 @@ static struct in6_addr *net_if_ipv6_get_best_match(struct net_if *iface,
continue;
}
if (len == *best_so_far &&
ipv6->unicast[i].addr_state == NET_ADDR_DEPRECATED &&
addr_state == NET_ADDR_PREFERRED) {
/* We have a preferred address and a deprecated
* address. We prefer the preferred address if the
* prefix lengths are the same.
* See RFC 6724 chapter 5.
*/
continue;
}
addr_state = ipv6->unicast[i].addr_state;
NET_DBG("[%zd] Checking %s (%s) dst %s/%d", i,