From 1ef0ec55c9b2d6b4697dc9bcf2b5bf5bbe956fbd Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Tue, 19 Dec 2023 18:18:50 +1000 Subject: [PATCH] net: ip: dhcpv4: remove address on interface down Any received address is no longer valid once the interface goes down. Leaving the address assigned results in the L4 interface transitioning through the following on reconnection: UP: Interface is connected DOWN: Old address is removed by DHCP UP: New address is re-added by DHCP Signed-off-by: Jordan Yates --- subsys/net/ip/dhcpv4.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subsys/net/ip/dhcpv4.c b/subsys/net/ip/dhcpv4.c index 918b71d1d6..6285952e44 100644 --- a/subsys/net/ip/dhcpv4.c +++ b/subsys/net/ip/dhcpv4.c @@ -1163,6 +1163,10 @@ static void dhcpv4_iface_event_handler(struct net_mgmt_event_callback *cb, iface->config.dhcpv4.state = NET_DHCPV4_RENEWING; NET_DBG("enter state=%s", net_dhcpv4_state_name( iface->config.dhcpv4.state)); + /* Remove any bound address as interface is gone */ + if (!net_if_ipv4_addr_rm(iface, &iface->config.dhcpv4.requested_ip)) { + NET_DBG("Failed to remove addr from iface"); + } } } else if (mgmt_event == NET_EVENT_IF_UP) { NET_DBG("Interface %p coming up", iface);