Minor change: use goto instead of redundant code to return on error in dhcp_rev().

This commit is contained in:
goldsimon 2007-12-02 14:40:32 +00:00
parent e5a98b6a5b
commit 081e4d9209

View File

@ -1225,33 +1225,25 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
/* TODO: check packet length before reading them */ /* TODO: check packet length before reading them */
if (reply_msg->op != DHCP_BOOTREPLY) { if (reply_msg->op != DHCP_BOOTREPLY) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 1, ("not a DHCP reply message, but type %"U16_F"\n", (u16_t)reply_msg->op)); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 1, ("not a DHCP reply message, but type %"U16_F"\n", (u16_t)reply_msg->op));
pbuf_free(p); goto free_pbuf_and_return;
dhcp->p = NULL;
return;
} }
/* iterate through hardware address and match against DHCP message */ /* iterate through hardware address and match against DHCP message */
for (i = 0; i < netif->hwaddr_len; i++) { for (i = 0; i < netif->hwaddr_len; i++) {
if (netif->hwaddr[i] != reply_msg->chaddr[i]) { if (netif->hwaddr[i] != reply_msg->chaddr[i]) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 2, ("netif->hwaddr[%"U16_F"]==%02"X16_F" != reply_msg->chaddr[%"U16_F"]==%02"X16_F"\n", LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 2, ("netif->hwaddr[%"U16_F"]==%02"X16_F" != reply_msg->chaddr[%"U16_F"]==%02"X16_F"\n",
(u16_t)i, (u16_t)netif->hwaddr[i], (u16_t)i, (u16_t)reply_msg->chaddr[i])); (u16_t)i, (u16_t)netif->hwaddr[i], (u16_t)i, (u16_t)reply_msg->chaddr[i]));
pbuf_free(p); goto free_pbuf_and_return;
dhcp->p = NULL;
return;
} }
} }
/* match transaction ID against what we expected */ /* match transaction ID against what we expected */
if (ntohl(reply_msg->xid) != dhcp->xid) { if (ntohl(reply_msg->xid) != dhcp->xid) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 2, ("transaction id mismatch reply_msg->xid(%"X32_F")!=dhcp->xid(%"X32_F")\n",ntohl(reply_msg->xid),dhcp->xid)); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 2, ("transaction id mismatch reply_msg->xid(%"X32_F")!=dhcp->xid(%"X32_F")\n",ntohl(reply_msg->xid),dhcp->xid));
pbuf_free(p); goto free_pbuf_and_return;
dhcp->p = NULL;
return;
} }
/* option fields could be unfold? */ /* option fields could be unfold? */
if (dhcp_unfold_reply(dhcp) != ERR_OK) { if (dhcp_unfold_reply(dhcp) != ERR_OK) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 2, ("problem unfolding DHCP message - too short on memory?\n")); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 2, ("problem unfolding DHCP message - too short on memory?\n"));
pbuf_free(p); goto free_pbuf_and_return;
dhcp->p = NULL;
return;
} }
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE\n")); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE\n"));
@ -1259,9 +1251,7 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE); options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE);
if (options_ptr == NULL) { if (options_ptr == NULL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 1, ("DHCP_OPTION_MESSAGE_TYPE option not found\n")); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 1, ("DHCP_OPTION_MESSAGE_TYPE option not found\n"));
pbuf_free(p); goto free_pbuf_and_return;
dhcp->p = NULL;
return;
} }
/* read DHCP message type */ /* read DHCP message type */
@ -1302,6 +1292,7 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
/* remember offered lease */ /* remember offered lease */
dhcp_handle_offer(netif); dhcp_handle_offer(netif);
} }
free_pbuf_and_return:
pbuf_free(p); pbuf_free(p);
dhcp->p = NULL; dhcp->p = NULL;
} }