[PATCH 07/10] net: lwip: allow DHCP to stop without releasing its lease
James Hilliard <[email protected]>
| Newsgroups | org.u-boot-project.lists.u-boot |
|---|---|
| Message-ID | <20260825-submit-lwip-runtime-netconsole-v1-v1-7-0892966aa758@gmail.com> |
U-Boot keeps using the address acquired by the dhcp command. The existing lwIP stop operation sends DHCPRELEASE and clears the interface address, which is unsuitable when the interface remains active for another client. Factor the common shutdown path and add dhcp_stop_without_release(). It stops the state machine and drops its UDP PCB reference without sending DHCPRELEASE or clearing the interface address. Signed-off-by: James Hilliard <[email protected]> --- lib/lwip/lwip/src/core/ipv4/dhcp.c | 39 ++++++++++++++++++++++++++--------- lib/lwip/lwip/src/include/lwip/dhcp.h | 1 + 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/lwip/lwip/src/core/ipv4/dhcp.c b/lib/lwip/lwip/src/core/ipv4/dhcp.c index d9ed8b0f37a..bfc6cfe488e 100644 --- a/lib/lwip/lwip/src/core/ipv4/dhcp.c +++ b/lib/lwip/lwip/src/core/ipv4/dhcp.c @@ -1315,20 +1315,15 @@ dhcp_reboot(struct netif *netif) return result; } -/** - * @ingroup dhcp4 - * Release a DHCP lease and stop DHCP statemachine (and AUTOIP if LWIP_DHCP_AUTOIP_COOP). - * - * @param netif network interface - */ -void -dhcp_release_and_stop(struct netif *netif) +/** Stop the DHCP state machine, optionally releasing its lease. */ +static void +dhcp_stop_internal(struct netif *netif, int release) { struct dhcp *dhcp = netif_dhcp_data(netif); ip_addr_t server_ip_addr; LWIP_ASSERT_CORE_LOCKED(); - LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_release_and_stop()\n")); + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop_internal()\n")); if (dhcp == NULL) { return; } @@ -1352,7 +1347,7 @@ dhcp_release_and_stop(struct netif *netif) dhcp->t1_renew_time = dhcp->t2_rebind_time = dhcp->lease_used = dhcp->t0_timeout = 0; /* send release message when current IP was assigned via DHCP */ - if (dhcp_supplied_address(netif)) { + if (release && dhcp_supplied_address(netif)) { /* create and initialize the DHCP message header */ struct pbuf *p_out; u16_t options_out_len; @@ -1391,6 +1386,30 @@ dhcp_release_and_stop(struct netif *netif) } } +/** + * @ingroup dhcp4 + * Stop DHCP without sending DHCPRELEASE or removing the configured address. + * + * @param netif network interface + */ +void +dhcp_stop_without_release(struct netif *netif) +{ + dhcp_stop_internal(netif, 0); +} + +/** + * @ingroup dhcp4 + * Release a DHCP lease and stop DHCP statemachine (and AUTOIP if LWIP_DHCP_AUTOIP_COOP). + * + * @param netif network interface + */ +void +dhcp_release_and_stop(struct netif *netif) +{ + dhcp_stop_internal(netif, 1); +} + /** * @ingroup dhcp4 * This function calls dhcp_release_and_stop() internally. diff --git a/lib/lwip/lwip/src/include/lwip/dhcp.h b/lib/lwip/lwip/src/include/lwip/dhcp.h index b413fa63f96..e7a79174f54 100644 --- a/lib/lwip/lwip/src/include/lwip/dhcp.h +++ b/lib/lwip/lwip/src/include/lwip/dhcp.h @@ -127,6 +127,7 @@ err_t dhcp_start(struct netif *netif); err_t dhcp_renew(struct netif *netif); err_t dhcp_release(struct netif *netif); void dhcp_stop(struct netif *netif); +void dhcp_stop_without_release(struct netif *netif); void dhcp_release_and_stop(struct netif *netif); void dhcp_inform(struct netif *netif); void dhcp_network_changed_link_up(struct netif *netif); -- 2.53.0