From 3a788b6e8b4b39e07a2cc700c7cf7f0291ee52dd Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Wed, 12 May 2021 21:04:46 +0200 Subject: [PATCH] dhcp: remove acd handle when stopping dhcp see bug #57706 --- src/core/ipv4/acd.c | 28 ++++++++++++++++++++++++++++ src/core/ipv4/dhcp.c | 8 ++++++++ src/include/lwip/acd.h | 7 +------ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/core/ipv4/acd.c b/src/core/ipv4/acd.c index 90e0decf..8f4b54a0 100644 --- a/src/core/ipv4/acd.c +++ b/src/core/ipv4/acd.c @@ -141,6 +141,34 @@ acd_add(struct netif *netif, struct acd *acd, return ERR_OK; } +/** + * @ingroup acd + * Remvoe ACD client from the client list + * + * @param netif network interface from which to remove the acd client + * @param acd acd module to be removed from the list + */ +void +acd_remove(struct netif *netif, struct acd *acd) +{ + struct acd *acd2, *prev = NULL; + + LWIP_ASSERT_CORE_LOCKED(); + + for (acd2 = netif->acd_list; acd2 != NULL; acd2 = acd2->next) { + if (acd2 == acd) { + if (prev) { + prev->next = acd->next; + } else { + netif->acd_list = acd->next; + } + return; + } + } + LWIP_ASSERT(0, ("acd_remove(): acd not on list\n")); +} + + /** * @ingroup acd * Start ACD client diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index e05a093b..21979d20 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -308,6 +308,9 @@ dhcp_conflict_callback(struct netif *netif, acd_callback_enum_t state) struct dhcp *dhcp = netif_dhcp_data(netif); u16_t msecs; + LWIP_ASSERT("DHCP should be enabled at this point, but it is not!", + (dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)); + switch (state) { case ACD_IP_OK: dhcp_bind(netif); @@ -1361,6 +1364,11 @@ dhcp_release_and_stop(struct netif *netif) dhcp_set_state(dhcp, DHCP_STATE_OFF); } +#if LWIP_DHCP_DOES_ACD_CHECK + /* stop acd because we may be in checking state and the callback would trigger a bind */ + acd_remove(netif, &dhcp->acd); +#endif + if (dhcp->pcb_allocated != 0) { dhcp_dec_pcb_refcount(); /* free DHCP PCB if not needed any more */ dhcp->pcb_allocated = 0; diff --git a/src/include/lwip/acd.h b/src/include/lwip/acd.h index a5f36586..e2e6cddf 100644 --- a/src/include/lwip/acd.h +++ b/src/include/lwip/acd.h @@ -91,17 +91,12 @@ struct acd err_t acd_add(struct netif *netif, struct acd *acd, acd_conflict_callback_t acd_conflict_callback); - +void acd_remove(struct netif *netif, struct acd *acd); err_t acd_start(struct netif *netif, struct acd *acd, ip4_addr_t ipaddr); - err_t acd_stop(struct acd *acd); - void acd_arp_reply(struct netif *netif, struct etharp_hdr *hdr); - void acd_tmr(void); - void acd_network_changed_link_down(struct netif *netif); - void acd_netif_ip_addr_changed(struct netif *netif, const ip_addr_t *old_addr, const ip_addr_t *new_addr);