Skip to content

Commit

Permalink
dhcp: Add dhcp state debug info
Browse files Browse the repository at this point in the history
Picked from 9c62fd4e
Ref IDF-4817
  • Loading branch information
freakyxue authored and david-cermak committed Aug 16, 2022
1 parent 84e0273 commit 1343f47
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/core/ipv4/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ dhcp_handle_nak(struct netif *netif)
/* Change to a defined state - set this before assigning the address
to ensure the callback can use dhcp_supplied_address() */
dhcp_set_state(dhcp, DHCP_STATE_BACKING_OFF);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_nak(): dhcp state is BACKING_OFF\n"));
/* remove IP address from interface (must no longer be used, as per RFC2131) */
netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
/* We can immediately restart discovery */
Expand All @@ -343,6 +344,7 @@ dhcp_check(struct netif *netif)
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (s16_t)netif->name[0],
(s16_t)netif->name[1]));
dhcp_set_state(dhcp, DHCP_STATE_CHECKING);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_check(): dhcp state is CHECKING\n"));
/* create an ARP query for the offered IP address, expecting that no host
responds, as the IP address should not be in use. */
result = etharp_query(netif, &dhcp->offered_ip_addr, NULL);
Expand Down Expand Up @@ -413,6 +415,7 @@ dhcp_select(struct netif *netif)

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_select(netif=%p) %c%c%"U16_F"\n", (void *)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
dhcp_set_state(dhcp, DHCP_STATE_REQUESTING);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_select(): dhcp state is REQUESTING\n"));

/* create and initialize the DHCP message header */
p_out = dhcp_create_msg(netif, dhcp, DHCP_REQUEST, &options_out_len);
Expand Down Expand Up @@ -832,6 +835,7 @@ dhcp_start(struct netif *netif)
if (!netif_is_link_up(netif)) {
/* set state INIT and wait for dhcp_network_changed() to call dhcp_discover() */
dhcp_set_state(dhcp, DHCP_STATE_INIT);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_start(): dhcp state is INIT\n"));
return ERR_OK;
}

Expand Down Expand Up @@ -877,7 +881,7 @@ dhcp_inform(struct netif *netif)

memset(&dhcp, 0, sizeof(struct dhcp));
dhcp_set_state(&dhcp, DHCP_STATE_INFORMING);

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_inform(): dhcp state is INFORMING\n"));
/* create and initialize the DHCP message header */
p_out = dhcp_create_msg(netif, &dhcp, DHCP_INFORM, &options_out_len);
if (p_out != NULL) {
Expand Down Expand Up @@ -993,6 +997,7 @@ dhcp_decline(struct netif *netif)

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline()\n"));
dhcp_set_state(dhcp, DHCP_STATE_BACKING_OFF);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_decline(): dhcp state is BACKING_OFF\n"));
/* create and initialize the DHCP message header */
p_out = dhcp_create_msg(netif, dhcp, DHCP_DECLINE, &options_out_len);
if (p_out != NULL) {
Expand Down Expand Up @@ -1042,6 +1047,8 @@ dhcp_discover(struct netif *netif)

ip4_addr_set_any(&dhcp->offered_ip_addr);
dhcp_set_state(dhcp, DHCP_STATE_SELECTING);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_discover(): dhcp state is DISCOVER\n"));
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("dhcp_select: could not allocate DHCP request\n"));
/* create and initialize the DHCP message header */
p_out = dhcp_create_msg(netif, dhcp, DHCP_DISCOVER, &options_out_len);
if (p_out != NULL) {
Expand Down Expand Up @@ -1161,7 +1168,7 @@ dhcp_bind(struct netif *netif)
/* netif is now bound to DHCP leased address - set this before assigning the address
to ensure the callback can use dhcp_supplied_address() */
dhcp_set_state(dhcp, DHCP_STATE_BOUND);

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): dhcp state is BOUND\n"));
netif_set_addr(netif, &dhcp->offered_ip_addr, &sn_mask, &gw_addr);
/* interface is used by routing now that an address is set */
}
Expand All @@ -1185,7 +1192,7 @@ dhcp_renew(struct netif *netif)
LWIP_ASSERT_CORE_LOCKED();
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_renew()\n"));
dhcp_set_state(dhcp, DHCP_STATE_RENEWING);

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_renew(): dhcp state is RENEWING\n"));
/* create and initialize the DHCP message header */
p_out = dhcp_create_msg(netif, dhcp, DHCP_REQUEST, &options_out_len);
if (p_out != NULL) {
Expand Down Expand Up @@ -1240,7 +1247,7 @@ dhcp_rebind(struct netif *netif)

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_rebind()\n"));
dhcp_set_state(dhcp, DHCP_STATE_REBINDING);

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_rebind(): dhcp state is REBINDING\n"));
/* create and initialize the DHCP message header */
p_out = dhcp_create_msg(netif, dhcp, DHCP_REQUEST, &options_out_len);
if (p_out != NULL) {
Expand Down Expand Up @@ -1294,7 +1301,7 @@ dhcp_reboot(struct netif *netif)

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_reboot()\n"));
dhcp_set_state(dhcp, DHCP_STATE_REBOOTING);

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_reboot(): dhcp state is REBOOTING\n"));
/* create and initialize the DHCP message header */
p_out = dhcp_create_msg(netif, dhcp, DHCP_REQUEST, &options_out_len);
if (p_out != NULL) {
Expand Down Expand Up @@ -1406,6 +1413,7 @@ dhcp_release_and_stop(struct netif *netif)
}
#endif /* LWIP_DHCP_AUTOIP_COOP */

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_release_and_stop(): dhcp state is OFF\n"));
if (dhcp->pcb_allocated != 0) {
dhcp_dec_pcb_refcount(); /* free DHCP PCB if not needed any more */
dhcp->pcb_allocated = 0;
Expand Down

0 comments on commit 1343f47

Please sign in to comment.