mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-09-25 02:03:39 +08:00
Documentation changes. Added missing trailing newlines to debug messages.
This commit is contained in:
178
src/core/dhcp.c
178
src/core/dhcp.c
@@ -138,9 +138,9 @@ static void dhcp_option_trailer(struct dhcp *dhcp);
|
||||
static void dhcp_handle_nak(struct netif *netif) {
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
u16_t msecs = 10 * 1000;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_handle_nak()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_handle_nak()\n"));
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %u msecs", msecs));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %u msecs\n", msecs));
|
||||
dhcp_set_state(dhcp, DHCP_BACKING_OFF);
|
||||
}
|
||||
|
||||
@@ -157,12 +157,12 @@ static void dhcp_check(struct netif *netif)
|
||||
struct pbuf *p;
|
||||
err_t result;
|
||||
u16_t msecs;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check()\n"));
|
||||
/* create an ARP query for the offered IP address, expecting that no host
|
||||
responds, as the IP address should not be in use. */
|
||||
p = etharp_query(netif, &dhcp->offered_ip_addr, NULL);
|
||||
if (p != NULL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check(): sending ARP request len %u", p->tot_len));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check(): sending ARP request len %u\n", p->tot_len));
|
||||
result = netif->linkoutput(netif, p);
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
@@ -172,7 +172,7 @@ static void dhcp_check(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
msecs = 500;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %u msecs", msecs));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %u msecs\n", msecs));
|
||||
dhcp_set_state(dhcp, DHCP_CHECKING);
|
||||
}
|
||||
|
||||
@@ -189,10 +189,10 @@ static void dhcp_handle_offer(struct netif *netif)
|
||||
if (option_ptr != NULL)
|
||||
{
|
||||
dhcp->server_ip_addr.addr = htonl(dhcp_get_option_long(&option_ptr[2]));
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08lx", dhcp->server_ip_addr.addr));
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08lx\n", dhcp->server_ip_addr.addr));
|
||||
/* remember offered address */
|
||||
ip_addr_set(&dhcp->offered_ip_addr, (struct ip_addr *)&dhcp->msg_in->yiaddr);
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08lx", dhcp->offered_ip_addr.addr));
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08lx\n", dhcp->offered_ip_addr.addr));
|
||||
dhcp_select(netif);
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,7 @@ static err_t dhcp_select(struct netif *netif)
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
err_t result;
|
||||
u32_t msecs;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_select()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_select()\n"));
|
||||
|
||||
/* create and initialize the DHCP message header */
|
||||
result = dhcp_create_request(netif);
|
||||
@@ -255,7 +255,7 @@ static err_t dhcp_select(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %u msecs", msecs));
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %u msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -266,19 +266,19 @@ static err_t dhcp_select(struct netif *netif)
|
||||
void dhcp_coarse_tmr()
|
||||
{
|
||||
struct netif *netif = netif_list;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_coarse_tmr():"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_coarse_tmr()\n"));
|
||||
/* iterate through all network interfaces */
|
||||
while (netif != NULL) {
|
||||
/* only act on DHCP configured interfaces */
|
||||
if (netif->dhcp != NULL) {
|
||||
/* timer is active (non zero), and triggers (zeroes) now? */
|
||||
if (netif->dhcp->t2_timeout-- == 1) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout\n"));
|
||||
/* this clients' rebind timeout triggered */
|
||||
dhcp_t2_timeout(netif);
|
||||
/* timer is active (non zero), and triggers (zeroes) now */
|
||||
} else if (netif->dhcp->t1_timeout-- == 1) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout\n"));
|
||||
/* this clients' renewal timeout triggered */
|
||||
dhcp_t1_timeout(netif);
|
||||
}
|
||||
@@ -303,7 +303,7 @@ void dhcp_fine_tmr()
|
||||
if (netif->dhcp != NULL) {
|
||||
/* timer is active (non zero), and triggers (zeroes) now */
|
||||
if (netif->dhcp->request_timeout-- == 1) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_fine_tmr(): request timeout"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_fine_tmr(): request timeout\n"));
|
||||
/* this clients' request timeout triggered */
|
||||
dhcp_timeout(netif);
|
||||
}
|
||||
@@ -325,24 +325,24 @@ void dhcp_fine_tmr()
|
||||
static void dhcp_timeout(struct netif *netif)
|
||||
{
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_timeout()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_timeout()\n"));
|
||||
/* back-off period has passed, or server selection timed out */
|
||||
if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_timeout(): restarting discovery"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_timeout(): restarting discovery\n"));
|
||||
dhcp_discover(netif);
|
||||
/* receiving the requested lease timed out */
|
||||
} else if (dhcp->state == DHCP_REQUESTING) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out\n"));
|
||||
if (dhcp->tries <= 5) {
|
||||
dhcp_select(netif);
|
||||
} else {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting\n"));
|
||||
dhcp_release(netif);
|
||||
dhcp_discover(netif);
|
||||
}
|
||||
/* received no ARP reply for the offered address (which is good) */
|
||||
} else if (dhcp->state == DHCP_CHECKING) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): CHECKING, ARP request timed out"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): CHECKING, ARP request timed out\n"));
|
||||
if (dhcp->tries <= 1) {
|
||||
dhcp_check(netif);
|
||||
/* no ARP replies on the offered address,
|
||||
@@ -354,17 +354,17 @@ static void dhcp_timeout(struct netif *netif)
|
||||
}
|
||||
/* did not get response to renew request? */
|
||||
else if (dhcp->state == DHCP_RENEWING) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RENEWING, DHCP request timed out"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RENEWING, DHCP request timed out\n"));
|
||||
/* just retry renewal */
|
||||
/* note that the rebind timer will eventually time-out if renew does not work */
|
||||
dhcp_renew(netif);
|
||||
/* did not get response to rebind request? */
|
||||
} else if (dhcp->state == DHCP_REBINDING) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REBINDING, DHCP request timed out"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REBINDING, DHCP request timed out\n"));
|
||||
if (dhcp->tries <= 8) {
|
||||
dhcp_rebind(netif);
|
||||
} else {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RELEASING, DISCOVERING"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RELEASING, DISCOVERING\n"));
|
||||
dhcp_release(netif);
|
||||
dhcp_discover(netif);
|
||||
}
|
||||
@@ -379,11 +379,11 @@ static void dhcp_timeout(struct netif *netif)
|
||||
static void dhcp_t1_timeout(struct netif *netif)
|
||||
{
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_t1_timeout()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_t1_timeout()\n"));
|
||||
if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWING)) {
|
||||
/* just retry to renew */
|
||||
/* note that the rebind timer will eventually time-out if renew does not work */
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t1_timeout(): must renew"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t1_timeout(): must renew\n"));
|
||||
dhcp_renew(netif);
|
||||
}
|
||||
}
|
||||
@@ -395,10 +395,10 @@ static void dhcp_t1_timeout(struct netif *netif)
|
||||
static void dhcp_t2_timeout(struct netif *netif)
|
||||
{
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout()\n"));
|
||||
if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWING)) {
|
||||
/* just retry to rebind */
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout(): must rebind"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout(): must rebind\n"));
|
||||
dhcp_rebind(netif);
|
||||
}
|
||||
}
|
||||
@@ -485,13 +485,13 @@ err_t dhcp_start(struct netif *netif)
|
||||
err_t result = ERR_OK;
|
||||
|
||||
LWIP_ASSERT("netif != NULL", netif != NULL);
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_start(netif=%p) %c%c%u", netif, netif->name[0], netif->name[1], netif->num));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_start(netif=%p) %c%c%u\n", netif, netif->name[0], netif->name[1], netif->num));
|
||||
|
||||
if (dhcp == NULL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting new DHCP client"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting new DHCP client\n"));
|
||||
dhcp = mem_malloc(sizeof(struct dhcp));
|
||||
if (dhcp == NULL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not allocate dhcp"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not allocate dhcp\n"));
|
||||
netif->flags &= ~NETIF_FLAG_DHCP;
|
||||
return ERR_MEM;
|
||||
}
|
||||
@@ -500,7 +500,7 @@ err_t dhcp_start(struct netif *netif)
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): allocated dhcp"));
|
||||
dhcp->pcb = udp_new();
|
||||
if (dhcp->pcb == NULL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not obtain pcb"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not obtain pcb\n"));
|
||||
mem_free((void *)dhcp);
|
||||
dhcp = NULL;
|
||||
netif->flags &= ~NETIF_FLAG_DHCP;
|
||||
@@ -508,8 +508,8 @@ err_t dhcp_start(struct netif *netif)
|
||||
}
|
||||
/* store this dhcp client in the netif */
|
||||
netif->dhcp = dhcp;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): created new udp pcb"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting DHCP configuration"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): created new udp pcb\n"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting DHCP configuration\n"));
|
||||
} else {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE | 3, ("dhcp_start(): restarting DHCP configuration\n"));
|
||||
}
|
||||
@@ -538,19 +538,19 @@ void dhcp_inform(struct netif *netif)
|
||||
err_t result = ERR_OK;
|
||||
dhcp = mem_malloc(sizeof(struct dhcp));
|
||||
if (dhcp == NULL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not allocate dhcp"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not allocate dhcp\n"));
|
||||
return;
|
||||
}
|
||||
memset(dhcp, 0, sizeof(struct dhcp));
|
||||
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): allocated dhcp"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): allocated dhcp\n"));
|
||||
dhcp->pcb = udp_new();
|
||||
if (dhcp->pcb == NULL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not obtain pcb"));
|
||||
mem_free((void *)dhcp);
|
||||
return;
|
||||
}
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): created new udp pcb"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): created new udp pcb\n"));
|
||||
/* create and initialize the DHCP message header */
|
||||
result = dhcp_create_request(netif);
|
||||
if (result == ERR_OK) {
|
||||
@@ -593,15 +593,15 @@ void dhcp_inform(struct netif *netif)
|
||||
*/
|
||||
void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr)
|
||||
{
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_arp_reply()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_arp_reply()\n"));
|
||||
/* is this DHCP client doing an ARP check? */
|
||||
if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08lx", addr->addr));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08lx\n", addr->addr));
|
||||
/* did a host respond with the address we
|
||||
were offered by the DHCP server? */
|
||||
if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) {
|
||||
/* we will not accept the offered address */
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE | 1, ("dhcp_arp_reply(): arp reply matched with offered address, declining"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE | 1, ("dhcp_arp_reply(): arp reply matched with offered address, declining\n"));
|
||||
dhcp_decline(netif);
|
||||
}
|
||||
}
|
||||
@@ -619,7 +619,7 @@ static err_t dhcp_decline(struct netif *netif)
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
err_t result = ERR_OK;
|
||||
u16_t msecs;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_decline()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_decline()\n"));
|
||||
dhcp_set_state(dhcp, DHCP_BACKING_OFF);
|
||||
/* create and initialize the DHCP message header */
|
||||
result = dhcp_create_request(netif);
|
||||
@@ -646,7 +646,7 @@ static err_t dhcp_decline(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
msecs = 10*1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_decline(): set request timeout %u msecs", msecs));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_decline(): set request timeout %u msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -661,13 +661,13 @@ static err_t dhcp_discover(struct netif *netif)
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
err_t result = ERR_OK;
|
||||
u16_t msecs;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_discover()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_discover()\n"));
|
||||
ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY);
|
||||
/* create and initialize the DHCP message header */
|
||||
result = dhcp_create_request(netif);
|
||||
if (result == ERR_OK)
|
||||
{
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: making request"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: making request\n"));
|
||||
dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN);
|
||||
dhcp_option_byte(dhcp, DHCP_DISCOVER);
|
||||
|
||||
@@ -681,7 +681,7 @@ static err_t dhcp_discover(struct netif *netif)
|
||||
|
||||
dhcp_option_trailer(dhcp);
|
||||
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: realloc()ing"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_discover: realloc()ing\n"));
|
||||
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
|
||||
|
||||
/* set receive callback function with netif as user data */
|
||||
@@ -706,7 +706,7 @@ static err_t dhcp_discover(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
msecs = dhcp->tries < 4 ? (dhcp->tries + 1) * 1000 : 10 * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_discover(): set request timeout %u msecs", msecs));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_discover(): set request timeout %u msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -724,17 +724,17 @@ static void dhcp_bind(struct netif *netif)
|
||||
/* temporary DHCP lease? */
|
||||
if (dhcp->offered_t1_renew != 0xffffffffUL) {
|
||||
/* set renewal period timer */
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t1 renewal timer %lu secs", dhcp->offered_t1_renew));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t1 renewal timer %lu secs\n", dhcp->offered_t1_renew));
|
||||
dhcp->t1_timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
|
||||
if (dhcp->t1_timeout == 0) dhcp->t1_timeout = 1;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %u msecs", dhcp->offered_t1_renew*1000));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %u msecs\n", dhcp->offered_t1_renew*1000));
|
||||
}
|
||||
/* set renewal period timer */
|
||||
if (dhcp->offered_t2_rebind != 0xffffffffUL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t2 rebind timer %lu secs", dhcp->offered_t2_rebind));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t2 rebind timer %lu secs\n", dhcp->offered_t2_rebind));
|
||||
dhcp->t2_timeout = (dhcp->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
|
||||
if (dhcp->t2_timeout == 0) dhcp->t2_timeout = 1;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %u msecs", dhcp->offered_t2_rebind*1000));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_bind(): set request timeout %u msecs\n", dhcp->offered_t2_rebind*1000));
|
||||
}
|
||||
/* copy offered network mask */
|
||||
ip_addr_set(&sn_mask, &dhcp->offered_sn_mask);
|
||||
@@ -758,11 +758,11 @@ static void dhcp_bind(struct netif *netif)
|
||||
gw_addr.addr |= htonl(0x00000001);
|
||||
}
|
||||
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): IP: 0x%08lx", dhcp->offered_ip_addr.addr));
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): IP: 0x%08lx\n", dhcp->offered_ip_addr.addr));
|
||||
netif_set_ipaddr(netif, &dhcp->offered_ip_addr);
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): SN: 0x%08lx", sn_mask.addr));
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): SN: 0x%08lx\n", sn_mask.addr));
|
||||
netif_set_netmask(netif, &sn_mask);
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): GW: 0x%08lx", gw_addr.addr));
|
||||
DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): GW: 0x%08lx\n", gw_addr.addr));
|
||||
netif_set_gw(netif, &gw_addr);
|
||||
/* netif is now bound to DHCP leased address */
|
||||
dhcp_set_state(dhcp, DHCP_BOUND);
|
||||
@@ -778,7 +778,7 @@ err_t dhcp_renew(struct netif *netif)
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
err_t result;
|
||||
u16_t msecs;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_renew()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_renew()\n"));
|
||||
dhcp_set_state(dhcp, DHCP_RENEWING);
|
||||
|
||||
/* create and initialize the DHCP message header */
|
||||
@@ -819,7 +819,7 @@ err_t dhcp_renew(struct netif *netif)
|
||||
/* back-off on retries, but to a maximum of 20 seconds */
|
||||
msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %u msecs", msecs));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %u msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -833,7 +833,7 @@ static err_t dhcp_rebind(struct netif *netif)
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
err_t result;
|
||||
u16_t msecs;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind()\n"));
|
||||
dhcp_set_state(dhcp, DHCP_REBINDING);
|
||||
|
||||
/* create and initialize the DHCP message header */
|
||||
@@ -871,7 +871,7 @@ static err_t dhcp_rebind(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind(): set request timeout %u msecs", msecs));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind(): set request timeout %u msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -885,7 +885,7 @@ static err_t dhcp_release(struct netif *netif)
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
err_t result;
|
||||
u16_t msecs;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_release()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_release()\n"));
|
||||
|
||||
/* idle DHCP client */
|
||||
dhcp_set_state(dhcp, DHCP_OFF);
|
||||
@@ -912,7 +912,7 @@ static err_t dhcp_release(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_release(): set request timeout %u msecs", msecs));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_release(): set request timeout %u msecs\n", msecs));
|
||||
/* remove IP address from interface */
|
||||
netif_set_ipaddr(netif, IP_ADDR_ANY);
|
||||
netif_set_gw(netif, IP_ADDR_ANY);
|
||||
@@ -928,7 +928,7 @@ static err_t dhcp_release(struct netif *netif)
|
||||
void dhcp_stop(struct netif *netif)
|
||||
{
|
||||
struct dhcp *dhcp = netif->dhcp;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_stop()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_stop()\n"));
|
||||
/* netif is DHCP configured? */
|
||||
if (dhcp != NULL)
|
||||
{
|
||||
@@ -1027,14 +1027,14 @@ static err_t dhcp_unfold_reply(struct dhcp *dhcp)
|
||||
dhcp->options_in = mem_malloc(dhcp->options_in_len);
|
||||
if (dhcp->options_in == NULL)
|
||||
{
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->options"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->options\n"));
|
||||
return ERR_MEM;
|
||||
}
|
||||
}
|
||||
dhcp->msg_in = mem_malloc(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN);
|
||||
if (dhcp->msg_in == NULL)
|
||||
{
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->msg_in"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->msg_in\n"));
|
||||
mem_free((void *)dhcp->options_in);
|
||||
dhcp->options_in = NULL;
|
||||
return ERR_MEM;
|
||||
@@ -1053,7 +1053,7 @@ static err_t dhcp_unfold_reply(struct dhcp *dhcp)
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %u bytes into dhcp->msg_in[]", i));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %u bytes into dhcp->msg_in[]\n", i));
|
||||
if (dhcp->options_in != NULL) {
|
||||
ptr = (u8_t *)dhcp->options_in;
|
||||
/* proceed through options */
|
||||
@@ -1066,7 +1066,7 @@ static err_t dhcp_unfold_reply(struct dhcp *dhcp)
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %u bytes to dhcp->options_in[]", i));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_unfold_reply(): copied %u bytes to dhcp->options_in[]\n", i));
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
@@ -1087,7 +1087,7 @@ static void dhcp_free_reply(struct dhcp *dhcp)
|
||||
dhcp->options_in = NULL;
|
||||
dhcp->options_in_len = 0;
|
||||
}
|
||||
DEBUGF(DHCP_DEBUG, ("dhcp_free_reply(): freed"));
|
||||
DEBUGF(DHCP_DEBUG, ("dhcp_free_reply(): free'd\n"));
|
||||
}
|
||||
|
||||
|
||||
@@ -1102,18 +1102,18 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
|
||||
u8_t *options_ptr;
|
||||
u8_t msg_type;
|
||||
u8_t i;
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_recv()"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %u", p->len));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %u", p->tot_len));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_recv()\n"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %u\n", p->len));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %u\n", p->tot_len));
|
||||
dhcp->p = p;
|
||||
if (reply_msg->op != DHCP_BOOTREPLY) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("not a DHCP reply message, but type %u", reply_msg->op));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("not a DHCP reply message, but type %u\n", reply_msg->op));
|
||||
pbuf_free(p);
|
||||
}
|
||||
/* iterate through hardware address and match against DHCP message */
|
||||
for (i = 0; i < netif->hwaddr_len; i++) {
|
||||
if (netif->hwaddr[i] != reply_msg->chaddr[i]) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x",
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x\n",
|
||||
i, netif->hwaddr[i], i, reply_msg->chaddr[i]));
|
||||
pbuf_free(p);
|
||||
return;
|
||||
@@ -1121,22 +1121,22 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
|
||||
}
|
||||
/* match transaction ID against what we expected */
|
||||
if (ntohl(reply_msg->xid) != dhcp->xid) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("transaction id mismatch"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("transaction id mismatch\n"));
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
/* option fields could be unfold? */
|
||||
if (dhcp_unfold_reply(dhcp) != ERR_OK) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("problem unfolding DHCP message - too short on memory?"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("problem unfolding DHCP message - too short on memory?\n"));
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE\n"));
|
||||
/* obtain pointer to DHCP message type */
|
||||
options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE);
|
||||
if (options_ptr == NULL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OPTION_MESSAGE_TYPE option not found"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OPTION_MESSAGE_TYPE option not found\n"));
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
@@ -1145,7 +1145,7 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
|
||||
msg_type = dhcp_get_option_byte(options_ptr + 2);
|
||||
/* message type is DHCP ACK? */
|
||||
if (msg_type == DHCP_ACK) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_ACK received"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_ACK received\n"));
|
||||
/* in requesting state? */
|
||||
if (dhcp->state == DHCP_REQUESTING) {
|
||||
dhcp_handle_ack(netif);
|
||||
@@ -1168,13 +1168,13 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
|
||||
else if ((msg_type == DHCP_NAK) &&
|
||||
((dhcp->state == DHCP_REBOOTING) || (dhcp->state == DHCP_REQUESTING) ||
|
||||
(dhcp->state == DHCP_REBINDING) || (dhcp->state == DHCP_RENEWING ))) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_NAK received"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_NAK received\n"));
|
||||
dhcp->request_timeout = 0;
|
||||
dhcp_handle_nak(netif);
|
||||
}
|
||||
/* received a DHCP_OFFER in DHCP_SELECTING state? */
|
||||
else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_SELECTING)) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OFFER received in DHCP_SELECTING state"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OFFER received in DHCP_SELECTING state\n"));
|
||||
dhcp->request_timeout = 0;
|
||||
/* remember offered lease */
|
||||
dhcp_handle_offer(netif);
|
||||
@@ -1191,7 +1191,7 @@ static err_t dhcp_create_request(struct netif *netif)
|
||||
LWIP_ASSERT("dhcp_create_request: dhcp->msg_out == NULL", dhcp->msg_out == NULL);
|
||||
dhcp->p_out = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg), PBUF_RAM);
|
||||
if (dhcp->p_out == NULL) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_create_request(): could not allocate pbuf"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_create_request(): could not allocate pbuf\n"));
|
||||
return ERR_MEM;
|
||||
}
|
||||
/* give unique transaction identifier to this request */
|
||||
@@ -1244,13 +1244,13 @@ static void dhcp_delete_request(struct netif *netif)
|
||||
|
||||
static void dhcp_option_trailer(struct dhcp *dhcp)
|
||||
{
|
||||
LWIP_ASSERT("dhcp_option_trailer: dhcp->msg_out != NULL", dhcp->msg_out != NULL);
|
||||
LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN", dhcp->options_out_len < DHCP_OPTIONS_LEN);
|
||||
LWIP_ASSERT("dhcp_option_trailer: dhcp->msg_out != NULL\n", dhcp->msg_out != NULL);
|
||||
LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", dhcp->options_out_len < DHCP_OPTIONS_LEN);
|
||||
dhcp->msg_out->options[dhcp->options_out_len++] = DHCP_OPTION_END;
|
||||
/* packet is too small, or not 4 byte aligned? */
|
||||
while ((dhcp->options_out_len < DHCP_MIN_OPTIONS_LEN) || (dhcp->options_out_len & 3)) {
|
||||
/* DEBUGF(DHCP_DEBUG, ("dhcp_option_trailer: dhcp->options_out_len=%u, DHCP_OPTIONS_LEN=%u", dhcp->options_out_len, DHCP_OPTIONS_LEN)); */
|
||||
LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN", dhcp->options_out_len < DHCP_OPTIONS_LEN);
|
||||
LWIP_ASSERT("dhcp_option_trailer: dhcp->options_out_len < DHCP_OPTIONS_LEN\n", dhcp->options_out_len < DHCP_OPTIONS_LEN);
|
||||
/* add a fill/padding byte */
|
||||
dhcp->msg_out->options[dhcp->options_out_len++] = 0;
|
||||
}
|
||||
@@ -1279,18 +1279,18 @@ static u8_t *dhcp_get_option_ptr(struct dhcp *dhcp, u8_t option_type)
|
||||
/* DEBUGF(DHCP_DEBUG, ("msg_offset=%u, q->len=%u", msg_offset, q->len)); */
|
||||
/* are the sname and/or file field overloaded with options? */
|
||||
if (options[offset] == DHCP_OPTION_OVERLOAD) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("overloaded message detected"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("overloaded message detected\n"));
|
||||
/* skip option type and length */
|
||||
offset += 2;
|
||||
overload = options[offset++];
|
||||
}
|
||||
/* requested option found */
|
||||
else if (options[offset] == option_type) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset %u in options", offset));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset %u in options\n", offset));
|
||||
return &options[offset];
|
||||
/* skip option */
|
||||
} else {
|
||||
DEBUGF(DHCP_DEBUG, ("skipping option %u in options", options[offset]));
|
||||
DEBUGF(DHCP_DEBUG, ("skipping option %u in options\n", options[offset]));
|
||||
/* skip option type */
|
||||
offset++;
|
||||
/* skip option length, and then length bytes */
|
||||
@@ -1301,16 +1301,16 @@ static u8_t *dhcp_get_option_ptr(struct dhcp *dhcp, u8_t option_type)
|
||||
if (overload != DHCP_OVERLOAD_NONE) {
|
||||
u16_t field_len;
|
||||
if (overload == DHCP_OVERLOAD_FILE) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded file field"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded file field\n"));
|
||||
options = (u8_t *)&dhcp->msg_in->file;
|
||||
field_len = DHCP_FILE_LEN;
|
||||
} else if (overload == DHCP_OVERLOAD_SNAME) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname field"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname field\n"));
|
||||
options = (u8_t *)&dhcp->msg_in->sname;
|
||||
field_len = DHCP_SNAME_LEN;
|
||||
/* TODO: check if else if () is necessary */
|
||||
} else {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname and file field"));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname and file field\n"));
|
||||
options = (u8_t *)&dhcp->msg_in->sname;
|
||||
field_len = DHCP_FILE_LEN + DHCP_SNAME_LEN;
|
||||
}
|
||||
@@ -1319,11 +1319,11 @@ static u8_t *dhcp_get_option_ptr(struct dhcp *dhcp, u8_t option_type)
|
||||
/* at least 1 byte to read and no end marker */
|
||||
while ((offset < field_len) && (options[offset] != DHCP_OPTION_END)) {
|
||||
if (options[offset] == option_type) {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset=%u", offset));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset=%u\n", offset));
|
||||
return &options[offset];
|
||||
/* skip option */
|
||||
} else {
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("skipping option %u", options[offset]));
|
||||
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("skipping option %u\n", options[offset]));
|
||||
/* skip option type */
|
||||
offset++;
|
||||
offset += 1 + options[offset];
|
||||
@@ -1344,7 +1344,7 @@ static u8_t *dhcp_get_option_ptr(struct dhcp *dhcp, u8_t option_type)
|
||||
*/
|
||||
static u8_t dhcp_get_option_byte(u8_t *ptr)
|
||||
{
|
||||
DEBUGF(DHCP_DEBUG, ("option byte value=%u", *ptr));
|
||||
DEBUGF(DHCP_DEBUG, ("option byte value=%u\n", *ptr));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
@@ -1361,7 +1361,7 @@ static u16_t dhcp_get_option_short(u8_t *ptr)
|
||||
u16_t value;
|
||||
value = *ptr++ << 8;
|
||||
value |= *ptr;
|
||||
DEBUGF(DHCP_DEBUG, ("option short value=%u", value));
|
||||
DEBUGF(DHCP_DEBUG, ("option short value=%u\n", value));
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1380,6 +1380,6 @@ static u32_t dhcp_get_option_long(u8_t *ptr)
|
||||
value |= (u32_t)(*ptr++) << 16;
|
||||
value |= (u32_t)(*ptr++) << 8;
|
||||
value |= (u32_t)(*ptr++);
|
||||
DEBUGF(DHCP_DEBUG, ("option long value=%lu", value));
|
||||
DEBUGF(DHCP_DEBUG, ("option long value=%lu\n", value));
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
|
||||
/* remote port is DHCP server? */
|
||||
if(IPH_PROTO(iphdr) == IP_PROTO_UDP) {
|
||||
DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: UDP packet to DHCP client port %u\n",
|
||||
ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest)));
|
||||
ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest)));
|
||||
if (ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest) == DHCP_CLIENT_PORT) {
|
||||
DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: DHCP packet accepted.\n"));
|
||||
netif = inp;
|
||||
|
||||
@@ -143,7 +143,7 @@ void netif_remove(struct netif * netif)
|
||||
/* reset default netif */
|
||||
netif_default = NULL;
|
||||
|
||||
DEBUGF(NETIF_DEBUG, ("netif_remove: removed netif"));
|
||||
DEBUGF(NETIF_DEBUG, ("netif_remove: removed netif\n"));
|
||||
mem_free( netif );
|
||||
}
|
||||
|
||||
|
||||
107
src/core/pbuf.c
107
src/core/pbuf.c
@@ -1,6 +1,15 @@
|
||||
/**
|
||||
* @file
|
||||
* Packet buffers/chains management module
|
||||
* Packet buffer management
|
||||
*
|
||||
* Packets are represented by the pbuf data structure. It supports dynamic
|
||||
* memory allocation for packet contents or can reference externally
|
||||
* managed packet contents both in RAM and ROM. Quick allocation for
|
||||
* incoming packets is provided through pools with fixed sized pbufs.
|
||||
*
|
||||
* Pbufs can be chained as a singly linked list, called a pbuf chain, so
|
||||
* that a packet may span over several pbufs.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -60,7 +69,6 @@ static struct pbuf *pbuf_pool_alloc_cache = NULL;
|
||||
static struct pbuf *pbuf_pool_free_cache = NULL;
|
||||
|
||||
/**
|
||||
*
|
||||
* Initializes the pbuf module.
|
||||
*
|
||||
* A large part of memory is allocated for holding the pool of pbufs.
|
||||
@@ -189,12 +197,14 @@ pbuf_pool_free(struct pbuf *p)
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a pbuf.
|
||||
*
|
||||
* Allocates a pbuf at protocol layer l.
|
||||
* The actual memory allocated for the pbuf is determined by the
|
||||
* layer at which the pbuf is allocated and the requested size
|
||||
* (from the size parameter). The flag parameter decides how and
|
||||
* where the pbuf should be allocated as follows:
|
||||
* (from the size parameter).
|
||||
*
|
||||
* @param flag this parameter decides how and where the pbuf
|
||||
* should be allocated as follows:
|
||||
*
|
||||
* - PBUF_RAM: buffer memory for pbuf is allocated as one large
|
||||
* chunk. This includes protocol headers as well.
|
||||
@@ -211,13 +221,16 @@ pbuf_pool_free(struct pbuf *p)
|
||||
* then pbuf_take should be called to copy the buffer.
|
||||
* - PBUF_POOL: the pbuf is allocated as a pbuf chain, with pbufs from
|
||||
* the pbuf pool that is allocated during pbuf_init().
|
||||
*
|
||||
* @return the allocated pbuf. If multiple pbufs where allocated, this
|
||||
* is the first pbuf of a pbuf chain.
|
||||
*/
|
||||
struct pbuf *
|
||||
pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
|
||||
pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
|
||||
{
|
||||
struct pbuf *p, *q, *r;
|
||||
u16_t offset;
|
||||
s32_t rem_len;
|
||||
s32_t rem_len; /* remaining length */
|
||||
|
||||
/* determine header offset */
|
||||
offset = 0;
|
||||
@@ -250,17 +263,19 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
|
||||
}
|
||||
p->next = NULL;
|
||||
|
||||
/* make the payload pointer points offset bytes into pbuf data memory */
|
||||
/* make the payload pointer point offset bytes into pbuf data memory */
|
||||
p->payload = MEM_ALIGN((void *)((u8_t *)p + (sizeof(struct pbuf) + offset)));
|
||||
/* the total length of the pbuf is the requested size */
|
||||
p->tot_len = size;
|
||||
/* set the length of the first pbuf is the chain */
|
||||
p->len = size > PBUF_POOL_BUFSIZE - offset? PBUF_POOL_BUFSIZE - offset: size;
|
||||
p->tot_len = length;
|
||||
/* set the length of the first pbuf in the chain */
|
||||
p->len = length > PBUF_POOL_BUFSIZE - offset? PBUF_POOL_BUFSIZE - offset: length;
|
||||
p->flags = PBUF_FLAG_POOL;
|
||||
|
||||
/* allocate the tail of the pbuf chain. */
|
||||
r = p;
|
||||
rem_len = size - p->len;
|
||||
/* remaining length to be allocated */
|
||||
rem_len = length - p->len;
|
||||
/* any remaining pbufs to be allocated? */
|
||||
while(rem_len > 0) {
|
||||
q = pbuf_pool_alloc();
|
||||
if (q == NULL) {
|
||||
@@ -279,7 +294,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
|
||||
q->payload = (void *)((u8_t *)q + sizeof(struct pbuf));
|
||||
r = q;
|
||||
q->ref = 1;
|
||||
rem_len -= PBUF_POOL_BUFSIZE;
|
||||
rem_len -= q->len;
|
||||
}
|
||||
/* end of chain */
|
||||
r->next = NULL;
|
||||
@@ -289,13 +304,13 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
|
||||
break;
|
||||
case PBUF_RAM:
|
||||
/* If pbuf is to be allocated in RAM, allocate memory for it. */
|
||||
p = mem_malloc(MEM_ALIGN_SIZE(sizeof(struct pbuf) + size + offset));
|
||||
p = mem_malloc(MEM_ALIGN_SIZE(sizeof(struct pbuf) + length + offset));
|
||||
if (p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
/* Set up internal structure of the pbuf. */
|
||||
p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf) + offset));
|
||||
p->len = p->tot_len = size;
|
||||
p->len = p->tot_len = length;
|
||||
p->next = NULL;
|
||||
p->flags = PBUF_FLAG_RAM;
|
||||
|
||||
@@ -314,7 +329,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag)
|
||||
}
|
||||
/* caller must set this field properly, afterwards */
|
||||
p->payload = NULL;
|
||||
p->len = p->tot_len = size;
|
||||
p->len = p->tot_len = length;
|
||||
p->next = NULL;
|
||||
p->flags = (flag == PBUF_ROM? PBUF_FLAG_ROM: PBUF_FLAG_REF);
|
||||
break;
|
||||
@@ -471,7 +486,7 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to decrease the payload pointer by the given header size.
|
||||
* Tries to add a header to the payload.
|
||||
*
|
||||
* Adjusts the ->payload pointer so that space for a header appears in
|
||||
* the pbuf. Also, the ->tot_len and ->len fields are adjusted.
|
||||
@@ -485,31 +500,32 @@ u8_t
|
||||
pbuf_header(struct pbuf *p, s16_t header_size)
|
||||
{
|
||||
void *payload;
|
||||
/* referencing pbufs cannot be realloc()ed */
|
||||
/* TODO: WHY NOT? just adjust payload, tot_len and len? */
|
||||
if (p->flags == PBUF_FLAG_ROM ||
|
||||
p->flags == PBUF_FLAG_REF) {
|
||||
/* failure */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* remember current payload pointer */
|
||||
payload = p->payload;
|
||||
/* set new payload pointer */
|
||||
p->payload = (u8_t *)p->payload - header_size;
|
||||
|
||||
DEBUGF(PBUF_DEBUG, ("pbuf_header: old %p new %p (%d)\n", payload, p->payload, header_size));
|
||||
|
||||
/* */
|
||||
if((u8_t *)p->payload < (u8_t *)p + sizeof(struct pbuf)) {
|
||||
DEBUGF(PBUF_DEBUG | 2, ("pbuf_header: failed as %p < %p\n",
|
||||
(u8_t *)p->payload,
|
||||
(u8_t *)p + sizeof(struct pbuf)));\
|
||||
/* restore old payload pointer */
|
||||
p->payload = payload;
|
||||
return 1;
|
||||
/* pbuf types containing payloads? */
|
||||
if (p->flags == PBUF_FLAG_RAM ||
|
||||
p->flags == PBUF_FLAG_POOL) {
|
||||
/* boundary check fails? */
|
||||
if ((u8_t *)p->payload < (u8_t *)p + sizeof(struct pbuf)) {
|
||||
DEBUGF( PBUF_DEBUG | 2, ("pbuf_header: failed as %p < %p\n",
|
||||
(u8_t *)p->payload,
|
||||
(u8_t *)p + sizeof(struct pbuf)) );\
|
||||
/* restore old payload pointer */
|
||||
p->payload = payload;/
|
||||
/* bail out unsuccesfully */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUGF( PBUF_DEBUG, ("pbuf_header: old %p new %p (%d)\n", payload, p->payload, header_size) );
|
||||
/* modify pbuf length fields */
|
||||
p->len += header_size;
|
||||
p->tot_len += header_size;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -547,7 +563,7 @@ pbuf_free(struct pbuf *p)
|
||||
SYS_ARCH_DECL_PROTECT(old_level);
|
||||
|
||||
if (p == NULL) {
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_free(p==NULL) was called.\n"));
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_free(p == NULL) was called.\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -575,7 +591,6 @@ pbuf_free(struct pbuf *p)
|
||||
{
|
||||
/* remember next pbuf in chain for next iteration */
|
||||
q = p->next;
|
||||
|
||||
/* is this a pbuf from the pool? */
|
||||
if (p->flags == PBUF_FLAG_POOL) {
|
||||
p->len = p->tot_len = PBUF_POOL_BUFSIZE;
|
||||
@@ -680,7 +695,7 @@ pbuf_chain(struct pbuf *h, struct pbuf *t)
|
||||
|
||||
/* proceed to last pbuf of chain */
|
||||
for (p = h; p->next != NULL; p = p->next) {
|
||||
/* add length of second chain to totals of first chain */
|
||||
/* add total length of second chain to each total of first chain */
|
||||
p->tot_len += t->tot_len;
|
||||
}
|
||||
/* chain last pbuf of h chain (p) with first of tail (t) */
|
||||
@@ -747,7 +762,7 @@ pbuf_take(struct pbuf *f)
|
||||
{
|
||||
struct pbuf *p, *prev, *top;
|
||||
LWIP_ASSERT("pbuf_take: f != NULL", f != NULL);
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 3, ("pbuf_take(%p)", (void*)f));
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 3, ("pbuf_take(%p)\n", (void*)f));
|
||||
|
||||
prev = NULL;
|
||||
p = f;
|
||||
@@ -760,21 +775,21 @@ pbuf_take(struct pbuf *f)
|
||||
{
|
||||
/* the replacement pbuf */
|
||||
struct pbuf *q;
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE, ("pbuf_take: encountered PBUF_REF %p", (void *)p));
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE, ("pbuf_take: encountered PBUF_REF %p\n", (void *)p));
|
||||
/* allocate a pbuf (w/ payload) fully in RAM */
|
||||
/* PBUF_POOL buffers are faster if we can use them */
|
||||
if (p->len <= PBUF_POOL_BUFSIZE) {
|
||||
q = pbuf_alloc(PBUF_RAW, p->len, PBUF_POOL);
|
||||
if (q == NULL) DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_take: Could not allocate PBUF_POOL"));
|
||||
if (q == NULL) DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_take: Could not allocate PBUF_POOL\n"));
|
||||
} else {
|
||||
/* no replacement pbuf yet */
|
||||
q = NULL;
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_take: PBUF_POOL too small to replace PBUF_REF"));
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_take: PBUF_POOL too small to replace PBUF_REF\n"));
|
||||
}
|
||||
/* no (large enough) PBUF_POOL was available? retry with PBUF_RAM */
|
||||
if (q == NULL) {
|
||||
q = pbuf_alloc(PBUF_RAW, p->len, PBUF_RAM);
|
||||
if (q == NULL) DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_take: Could not allocate PBUF_RAM"));
|
||||
if (q == NULL) DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_take: Could not allocate PBUF_RAM\n"));
|
||||
}
|
||||
/* replacement pbuf could be allocated? */
|
||||
if (q != NULL)
|
||||
@@ -816,13 +831,13 @@ pbuf_take(struct pbuf *f)
|
||||
}
|
||||
}
|
||||
else {
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 1, ("pbuf_take: not PBUF_REF"));
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 1, ("pbuf_take: not PBUF_REF\n"));
|
||||
}
|
||||
|
||||
prev = p;
|
||||
p = p->next;
|
||||
} while (p);
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 1, ("pbuf_take: end of chain reached."));
|
||||
DEBUGF(PBUF_DEBUG | DBG_TRACE | 1, ("pbuf_take: end of chain reached.\n"));
|
||||
|
||||
return top;
|
||||
}
|
||||
|
||||
@@ -470,22 +470,22 @@ tcp_slowtmr(void)
|
||||
/* Steps through all of the active PCBs. */
|
||||
prev = NULL;
|
||||
pcb = tcp_active_pcbs;
|
||||
if (pcb == NULL) DEBUGF(TCP_DEBUG, ("tcp_slowtmr: no active pcbs"));
|
||||
if (pcb == NULL) DEBUGF(TCP_DEBUG, ("tcp_slowtmr: no active pcbs\n"));
|
||||
while(pcb != NULL) {
|
||||
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: processing active pcb"));
|
||||
LWIP_ASSERT("tcp_slowtmr: active pcb->state != CLOSED", pcb->state != CLOSED);
|
||||
LWIP_ASSERT("tcp_slowtmr: active pcb->state != LISTEN", pcb->state != LISTEN);
|
||||
LWIP_ASSERT("tcp_slowtmr: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
|
||||
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: processing active pcb\n"));
|
||||
LWIP_ASSERT("tcp_slowtmr: active pcb->state != CLOSED\n", pcb->state != CLOSED);
|
||||
LWIP_ASSERT("tcp_slowtmr: active pcb->state != LISTEN\n", pcb->state != LISTEN);
|
||||
LWIP_ASSERT("tcp_slowtmr: active pcb->state != TIME-WAIT\n", pcb->state != TIME_WAIT);
|
||||
|
||||
pcb_remove = 0;
|
||||
|
||||
if(pcb->state == SYN_SENT && pcb->nrtx == TCP_SYNMAXRTX) {
|
||||
++pcb_remove;
|
||||
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max SYN retries reached"));
|
||||
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max SYN retries reached\n"));
|
||||
}
|
||||
else if(pcb->nrtx == TCP_MAXRTX) {
|
||||
++pcb_remove;
|
||||
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max DATA retries reached"));
|
||||
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max DATA retries reached\n"));
|
||||
} else {
|
||||
++pcb->rtime;
|
||||
if(pcb->unacked != NULL && pcb->rtime >= pcb->rto) {
|
||||
@@ -520,7 +520,7 @@ tcp_slowtmr(void)
|
||||
if((u32_t)(tcp_ticks - pcb->tmr) >
|
||||
TCP_FIN_WAIT_TIMEOUT / TCP_SLOW_INTERVAL) {
|
||||
++pcb_remove;
|
||||
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2"));
|
||||
DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user