From 902c95ab951b5fca2de0880d7c80bf5165bd4123 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Mon, 9 Jun 2025 13:43:49 +0300 Subject: [PATCH] net: if: Do not start ACD for localhost or point2point links When adding IPv4 address to the network interface, there is no need to start ACD procedure for localhost or point-to-point links. The ACD start function would mark the IP address like 127.0.0.1 as tentative and never make it preferred which would then cause issues when selecting the network address for sending. As the ACD start is also called when the network interface comes up, add the localhost and point-to-point link check to ACD start function so that we will avoid ACD checks in this case. Signed-off-by: Jukka Rissanen --- subsys/net/ip/net_if.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index b541787a0d9..b248b0b50d9 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -4402,6 +4402,11 @@ void net_if_ipv4_acd_failed(struct net_if *iface, struct net_if_addr *ifaddr) void net_if_ipv4_start_acd(struct net_if *iface, struct net_if_addr *ifaddr) { + if ((l2_flags_get(iface) & NET_L2_POINT_TO_POINT) || + net_ipv4_is_addr_loopback(&ifaddr->address.in_addr)) { + return; + } + ifaddr->addr_state = NET_ADDR_TENTATIVE; if (net_if_is_up(iface)) { @@ -4499,6 +4504,7 @@ struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface, struct net_if_addr *ifaddr = NULL; struct net_if_addr_ipv4 *cur; struct net_if_ipv4 *ipv4; + bool do_acd = false; int idx; net_if_lock(iface); @@ -4571,7 +4577,7 @@ struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface, !(l2_flags_get(iface) & NET_L2_POINT_TO_POINT) && !net_ipv4_is_addr_loopback(addr)) { /* ACD is started after the lock is released. */ - ; + do_acd = true; } else { ifaddr->addr_state = NET_ADDR_PREFERRED; } @@ -4584,7 +4590,9 @@ struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface, net_if_unlock(iface); - net_if_ipv4_start_acd(iface, ifaddr); + if (do_acd) { + net_if_ipv4_start_acd(iface, ifaddr); + } return ifaddr; }