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>
This commit is contained in:
Jordan Yates 2023-12-19 18:18:50 +10:00 committed by Carles Cufí
parent 434c93ddfb
commit 1ef0ec55c9

View file

@ -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);