optimization dhcp key state transition message

This commit is contained in:
xueyunfei
2020-04-14 17:01:04 +08:00
parent 595aef0d20
commit 9c62fd4e22
2 changed files with 15 additions and 6 deletions

View File

@ -286,6 +286,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(ESP_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);
if (dhcp->cb != NULL) {
@ -318,6 +319,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(ESP_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);
@ -388,6 +390,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(ESP_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);
@ -850,6 +853,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(ESP_DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_start(): dhcp state is INIT\n"));
return ERR_OK;
}
@ -858,6 +862,7 @@ dhcp_start(struct netif *netif)
/* If no valid ip is available, run dhcp_discover instead.*/
if(LWIP_DHCP_IP_ADDR_RESTORE()) {
dhcp_set_state(dhcp, DHCP_STATE_BOUND);
LWIP_DEBUGF(ESP_DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_start(): dhcp state is BOUND\n"));
dhcp_network_changed(netif);
return ERR_OK;
}
@ -899,7 +904,7 @@ dhcp_inform(struct netif *netif)
memset(&dhcp, 0, sizeof(struct dhcp));
dhcp_set_state(&dhcp, DHCP_STATE_INFORMING);
LWIP_DEBUGF(ESP_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) {
@ -1015,6 +1020,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(ESP_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) {
@ -1064,6 +1070,8 @@ dhcp_discover(struct netif *netif)
ip4_addr_set_any(&dhcp->offered_ip_addr);
dhcp_set_state(dhcp, DHCP_STATE_SELECTING);
LWIP_DEBUGF(ESP_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) {
@ -1263,7 +1271,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(ESP_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 */
@ -1301,7 +1309,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(ESP_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) {
@ -1356,7 +1364,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(ESP_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) {
@ -1410,7 +1418,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(ESP_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) {
@ -1528,7 +1536,7 @@ dhcp_release_and_stop(struct netif *netif)
#endif /* LWIP_DHCP_AUTOIP_COOP */
dhcp_set_state(dhcp, DHCP_STATE_OFF);
LWIP_DEBUGF(ESP_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;

View File

@ -102,6 +102,7 @@
#define ESP_LWIP_SELECT 1
#define ESP_LWIP_LOCK 1
#define TCP_OOSEQ_DEBUG LWIP_DBG_ON
#define ESP_DHCP_DEBUG 1
#ifdef IP_NAPT
#define IP_NAPT_MAX 16