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 <jordan.yates@data61.csiro.au>
diff --git a/subsys/net/ip/dhcpv4.c b/subsys/net/ip/dhcpv4.c
index 918b71d..6285952 100644
--- a/subsys/net/ip/dhcpv4.c
+++ b/subsys/net/ip/dhcpv4.c
@@ -1163,6 +1163,10 @@
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);