From bd4c0b746c12a39a324d28bfce13bf6ac8442098 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Mon, 9 Jun 2025 13:47:45 +0300 Subject: [PATCH] net: acd: Avoid removing auto IPv4 address twice When the network interface goes down, we call net_ipv4_autoconf_reset() which removes the autoaddress from the network interface. The net_ipv4_autoconf_reset() is also called when ACD is started in which case we could see this error message net_if_start_acd: Starting ACD for iface 2 net_if: iface 2 addr 169.254.174.230 (net_if_ipv4_addr_rm():4625) net_if_ipv4_addr_rm: Address 169.254.174.230 not found (-22) This error is superfluous and not needed. So before trying to remove the address, check if the interface already has it set and only then remove it. Signed-off-by: Jukka Rissanen --- subsys/net/ip/ipv4_autoconf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/subsys/net/ip/ipv4_autoconf.c b/subsys/net/ip/ipv4_autoconf.c index f08608f3b7e..057bd6f41a6 100644 --- a/subsys/net/ip/ipv4_autoconf.c +++ b/subsys/net/ip/ipv4_autoconf.c @@ -138,13 +138,18 @@ void net_ipv4_autoconf_start(struct net_if *iface) void net_ipv4_autoconf_reset(struct net_if *iface) { struct net_if_config *cfg; + struct net_if_addr *ifaddr; + struct net_if *ret; cfg = net_if_get_config(iface); if (!cfg) { return; } - net_if_ipv4_addr_rm(iface, &cfg->ipv4auto.requested_ip); + ifaddr = net_if_ipv4_addr_lookup(&cfg->ipv4auto.requested_ip, &ret); + if (ifaddr != NULL && ret == iface) { + net_if_ipv4_addr_rm(iface, &cfg->ipv4auto.requested_ip); + } NET_DBG("Autoconf reset for %p", iface); }