Skip to content

Commit

Permalink
dhcp: Restore dhcp_cb on restart after dhcp_release_and_stop()
Browse files Browse the repository at this point in the history
Closes #32
  • Loading branch information
david-cermak committed Jul 30, 2021
1 parent 74cf7f9 commit 55ea9d9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/ipv4/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,21 @@ dhcp_select(struct netif *netif)
return result;
}

#if ESP_DHCP
/**
* Restarts the DHCP client, typically after the dhcp_release_and_stop()
* This is equivalent to dhcp_start(), but preserves the dhcp callback
*/
static void
dhcp_restart(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
void (*cb)(struct netif*) = dhcp->cb;
dhcp_start(netif);
dhcp->cb = cb;
}
#endif /* ESP_DHCP */

/**
* The DHCP timer that checks for lease renewal/rebind timeouts.
* Must be called once a minute (see @ref DHCP_COARSE_TIMER_SECS).
Expand All @@ -461,7 +476,11 @@ dhcp_coarse_tmr(void)
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_coarse_tmr(): t0 timeout\n"));
/* this clients' lease time has expired */
dhcp_release_and_stop(netif);
#if ESP_DHCP
dhcp_restart(netif);
#else
dhcp_start(netif);
#endif /* ESP_DHCP */
/* timer is active (non zero), and triggers (zeroes) now? */
} else if (dhcp->t2_rebind_time && (dhcp->t2_rebind_time-- == 1)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout\n"));
Expand Down Expand Up @@ -533,7 +552,11 @@ dhcp_timeout(struct netif *netif)
} else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting\n"));
dhcp_release_and_stop(netif);
#if ESP_DHCP
dhcp_restart(netif);
#else
dhcp_start(netif);
#endif /* ESP_DHCP */
}
#if DHCP_DOES_ARP_CHECK
/* received no ARP reply for the offered address (which is good) */
Expand Down

0 comments on commit 55ea9d9

Please sign in to comment.