Skip to content

Commit da13b51

Browse files
jukkarkartben
authored andcommitted
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>
1 parent c58ae74 commit da13b51

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

subsys/net/ip/net_if.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,26 @@ static struct in6_addr *net_if_ipv6_get_best_match(struct net_if *iface,
31733173
len = prefix_len;
31743174
}
31753175

3176-
if (len >= *best_so_far) {
3176+
if (ipv6->unicast[i].addr_state == NET_ADDR_DEPRECATED &&
3177+
addr_state == NET_ADDR_PREFERRED) {
3178+
/* We have a preferred address and a deprecated
3179+
* address. We prefer always the preferred address
3180+
* over the deprecated address.
3181+
* See RFC 6724 chapter 5.
3182+
*/
3183+
NET_DBG("skipping deprecated address %s",
3184+
net_sprint_ipv6_addr(&ipv6->unicast[i].address.in6_addr));
3185+
continue;
3186+
}
3187+
3188+
if (len >= *best_so_far ||
3189+
(ipv6->unicast[i].addr_state == NET_ADDR_PREFERRED &&
3190+
addr_state == NET_ADDR_DEPRECATED)) {
3191+
/* Currently we have best deprecated address, but
3192+
* should now choose the preferred address regardless
3193+
* of the length.
3194+
*/
3195+
31773196
/* Mesh local address can only be selected for the same
31783197
* subnet.
31793198
*/
@@ -3182,17 +3201,6 @@ static struct in6_addr *net_if_ipv6_get_best_match(struct net_if *iface,
31823201
continue;
31833202
}
31843203

3185-
if (len == *best_so_far &&
3186-
ipv6->unicast[i].addr_state == NET_ADDR_DEPRECATED &&
3187-
addr_state == NET_ADDR_PREFERRED) {
3188-
/* We have a preferred address and a deprecated
3189-
* address. We prefer the preferred address if the
3190-
* prefix lengths are the same.
3191-
* See RFC 6724 chapter 5.
3192-
*/
3193-
continue;
3194-
}
3195-
31963204
addr_state = ipv6->unicast[i].addr_state;
31973205

31983206
NET_DBG("[%zd] Checking %s (%s) dst %s/%d", i,

0 commit comments

Comments
 (0)