diff --git a/doc/contrib.txt b/doc/contrib.txt index 90b0cb24..38d4bd48 100644 --- a/doc/contrib.txt +++ b/doc/contrib.txt @@ -3,30 +3,29 @@ How to contribute to lwIP Here is a short list of suggestions to anybody working with lwIP and trying to contribute bugreports, fixes, enhancements, platform ports etc. First of all as you may already know lwIP is a volunteer project so feedback -to fixes or questions might often come late.Hopefully the bug and patch tracking -features of savannah help us not lose users' input. +to fixes or questions might often come late. Hopefully the bug and patch tracking +features of Savannah help us not lose users' input. The suggestions: -- if you think you found a bug make sure it's not already filed in the bugtracker at savannah -- if you have a fix put the patch on savannah.If it's a patch that affects both core and arch specific +- If you think you found a bug make sure it's not already filed in the bugtracker at savannah +- If you have a fix put the patch on Savannah. If it's a patch that affects both core and arch specific stuff please separate them so that the core can be applied separately while leaving the other patch 'open' -The preffered way is to NOT touch archs you can't test and let maintainers take care of them.This is a good +The prefered way is to NOT touch archs you can't test and let maintainers take care of them. This is a good way to see if they are used at all - the same goes for unix netifs except tapif. -- do not file a bug and post a fix to it to the patch area.Either a bug report or a patch will be enough. -If you correct an existing bug then attach the patch to the bug rather than creating a new entry in the patch area. -- trivial patches (compiler warning, indentation and spelling fixes or anything obvious which takes a line or two) -can go to the lwip-users list.This is still the fastest way of interaction and the list is not so crowded -as to allow for loss of fixes.Putting bugs on savannah and subsequently closing them is too much an overhead -for repoting a compiler warning fix. +- Do not file a bug and post a fix to it to the patch area. Either a bug report or a patch will be enough. +If you correct an existing bug then attach the patch to the bug rather than creating a new entry in the patch area. +- Trivial patches (compiler warning, indentation and spelling fixes or anything obvious which takes a line or two) +can go to the lwip-users list. This is still the fastest way of interaction and the list is not so crowded +as to allow for loss of fixes. Putting bugs on Savannah and subsequently closing them is too much an overhead +for reporting a compiler warning fix. For platform porters: -- if you've ported lwIP to a platform (an OS, a uC/processor or a combination of these) and you think it +- If you've ported lwIP to a platform (an OS, a uC/processor or a combination of these) and you think it could benefit others[1] you might want to post an url to a tarball or zip from which it can be imported -to the contrib CVS module.Then you get CVS access and have to maintain your port :) - +to the contrib CVS module. Then you get CVS access and have to maintain your port :) [1] - lwIP CVS should not be just a place to keep your port so you don't have to set up your own CVS :) Especially welcome are ports to common enough OS/hardware that others can have access too. diff --git a/src/core/dhcp.c b/src/core/dhcp.c index 87aa3136..8eeb6e55 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -1,4 +1,11 @@ +/** + * @file + * + * Dynamic Host Configuration Protocol client + */ + /* + * * Copyright (c) 2001-2003 Leon Woestenberg * Copyright (c) 2001-2003 Axon Digital Design B.V., The Netherlands. * All rights reserved. @@ -131,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, ("dhcp_handle_nak()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_handle_nak()")); dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; - DEBUGF(DHCP_DEBUG, ("dhcp_handle_nak(): set request timeout %u msecs", msecs)); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %u msecs", msecs)); dhcp_set_state(dhcp, DHCP_BACKING_OFF); } @@ -150,12 +157,12 @@ static void dhcp_check(struct netif *netif) struct pbuf *p; err_t result; u16_t msecs; - DEBUGF(DHCP_DEBUG, ("dhcp_check()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check()")); /* 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, ("dhcp_check(): sending ARP request len %u", p->tot_len)); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_check(): sending ARP request len %u", p->tot_len)); result = netif->linkoutput(netif, p); pbuf_free(p); p = NULL; @@ -163,7 +170,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, ("dhcp_check(): set request timeout %u msecs", msecs)); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %u msecs", msecs)); dhcp_set_state(dhcp, DHCP_CHECKING); } @@ -180,10 +187,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, ("dhcp_handle_offer(): server 0x%08lx", dhcp->server_ip_addr.addr)); + DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08lx", 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, ("dhcp_handle_offer(): offer for 0x%08lx", dhcp->offered_ip_addr.addr)); + DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08lx", dhcp->offered_ip_addr.addr)); dhcp_select(netif); } } @@ -201,7 +208,7 @@ static err_t dhcp_select(struct netif *netif) struct dhcp *dhcp = netif->dhcp; err_t result; u32_t msecs; - DEBUGF(DHCP_DEBUG, ("dhcp_select()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_select()")); /* create and initialize the DHCP message header */ result = dhcp_create_request(netif); @@ -242,7 +249,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, ("dhcp_select(): set request timeout %u msecs", msecs)); + DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %u msecs", msecs)); dhcp_set_state(dhcp, DHCP_REQUESTING); return result; } @@ -254,19 +261,19 @@ static err_t dhcp_select(struct netif *netif) void dhcp_coarse_tmr() { struct netif *netif = netif_list; - DEBUGF(DHCP_DEBUG, ("dhcp_coarse_tmr():")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_coarse_tmr():")); /* 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, ("dhcp_coarse_tmr(): t2 timeout")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout")); /* 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, ("dhcp_coarse_tmr(): t1 timeout")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout")); /* this clients' renewal timeout triggered */ dhcp_t1_timeout(netif); } @@ -291,7 +298,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, ("dhcp_fine_tmr(): request timeout")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_fine_tmr(): request timeout")); /* this clients' request timeout triggered */ dhcp_timeout(netif); } @@ -313,24 +320,24 @@ void dhcp_fine_tmr() static void dhcp_timeout(struct netif *netif) { struct dhcp *dhcp = netif->dhcp; - DEBUGF(DHCP_DEBUG, ("dhcp_timeout()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_timeout()")); /* back-off period has passed, or server selection timed out */ if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) { - DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): restarting discovery")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_timeout(): restarting discovery")); dhcp_discover(netif); /* receiving the requested lease timed out */ } else if (dhcp->state == DHCP_REQUESTING) { - DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REQUESTING, DHCP request timed out")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out")); if (dhcp->tries <= 5) { dhcp_select(netif); } else { - DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): REQUESTING, releasing, restarting")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting")); 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, ("dhcp_timeout(): CHECKING, ARP request timed out")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): CHECKING, ARP request timed out")); if (dhcp->tries <= 1) { dhcp_check(netif); /* no ARP replies on the offered address, @@ -342,17 +349,17 @@ static void dhcp_timeout(struct netif *netif) } /* did not get response to renew request? */ else if (dhcp->state == DHCP_RENEWING) { - DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): RENEWING, DHCP request timed out")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RENEWING, DHCP request timed out")); /* 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, ("dhcp_timeout(): REBINDING, DHCP request timed out")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REBINDING, DHCP request timed out")); if (dhcp->tries <= 8) { dhcp_rebind(netif); } else { - DEBUGF(DHCP_DEBUG, ("dhcp_timeout(): RELEASING, DISCOVERING")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): RELEASING, DISCOVERING")); dhcp_release(netif); dhcp_discover(netif); } @@ -367,11 +374,11 @@ static void dhcp_timeout(struct netif *netif) static void dhcp_t1_timeout(struct netif *netif) { struct dhcp *dhcp = netif->dhcp; - DEBUGF(DHCP_DEBUG, ("dhcp_t1_timeout()")); + DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_t1_timeout()")); 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, ("dhcp_t1_timeout(): must renew")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t1_timeout(): must renew")); dhcp_renew(netif); } } @@ -383,10 +390,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, ("dhcp_t2_timeout()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout()")); if ((dhcp->state == DHCP_REQUESTING) || (dhcp->state == DHCP_BOUND) || (dhcp->state == DHCP_RENEWING)) { /* just retry to rebind */ - DEBUGF(DHCP_DEBUG, ("dhcp_t2_timeout(): must rebind")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_t2_timeout(): must rebind")); dhcp_rebind(netif); } } @@ -473,22 +480,22 @@ err_t dhcp_start(struct netif *netif) err_t result = ERR_OK; LWIP_ASSERT("netif != NULL", netif != NULL); - DEBUGF(DHCP_DEBUG, ("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", netif, netif->name[0], netif->name[1], netif->num)); if (dhcp == NULL) { - DEBUGF(DHCP_DEBUG, ("dhcp_start(): starting new DHCP client")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting new DHCP client")); dhcp = mem_malloc(sizeof(struct dhcp)); if (dhcp == NULL) { - DEBUGF(DHCP_DEBUG, ("dhcp_start(): could not allocate dhcp")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not allocate dhcp")); netif->flags &= ~NETIF_FLAG_DHCP; return ERR_MEM; } /* clear data structure */ memset(dhcp, 0, sizeof(struct dhcp)); - DEBUGF(DHCP_DEBUG, ("dhcp_start(): allocated dhcp")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): allocated dhcp")); dhcp->pcb = udp_new(); if (dhcp->pcb == NULL) { - DEBUGF(DHCP_DEBUG, ("dhcp_start(): could not obtain pcb")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): could not obtain pcb")); mem_free((void *)dhcp); dhcp = NULL; netif->flags &= ~NETIF_FLAG_DHCP; @@ -496,10 +503,10 @@ err_t dhcp_start(struct netif *netif) } /* store this dhcp client in the netif */ netif->dhcp = dhcp; - DEBUGF(DHCP_DEBUG, ("dhcp_start(): created new udp pcb")); - DEBUGF(DHCP_DEBUG, ("dhcp_start(): starting DHCP configuration")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): created new udp pcb")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): starting DHCP configuration")); } else { - DEBUGF(DHCP_DEBUG, ("dhcp_start(): restarting DHCP configuration")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_start(): restarting DHCP configuration")); } /* (re)start the DHCP negotiation */ result = dhcp_discover(netif); @@ -526,19 +533,19 @@ void dhcp_inform(struct netif *netif) err_t result = ERR_OK; dhcp = mem_malloc(sizeof(struct dhcp)); if (dhcp == NULL) { - DEBUGF(DHCP_DEBUG, ("dhcp_inform(): could not allocate dhcp")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not allocate dhcp")); return; } memset(dhcp, 0, sizeof(struct dhcp)); - DEBUGF(DHCP_DEBUG, ("dhcp_inform(): allocated dhcp")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): allocated dhcp")); dhcp->pcb = udp_new(); if (dhcp->pcb == NULL) { - DEBUGF(DHCP_DEBUG, ("dhcp_inform(): could not obtain pcb")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_inform(): could not obtain pcb")); mem_free((void *)dhcp); return; } - DEBUGF(DHCP_DEBUG, ("dhcp_inform(): created new udp pcb")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_inform(): created new udp pcb")); /* create and initialize the DHCP message header */ result = dhcp_create_request(netif); if (result == ERR_OK) { @@ -578,15 +585,15 @@ void dhcp_inform(struct netif *netif) */ void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr) { - DEBUGF(DHCP_DEBUG, ("dhcp_arp_reply()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_arp_reply()")); /* is this DHCP client doing an ARP check? */ if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) { - DEBUGF(DHCP_DEBUG, ("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", 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, ("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")); dhcp_decline(netif); } } @@ -604,7 +611,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, ("dhcp_decline()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_decline()")); dhcp_set_state(dhcp, DHCP_BACKING_OFF); /* create and initialize the DHCP message header */ result = dhcp_create_request(netif); @@ -628,7 +635,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, ("dhcp_decline(): set request timeout %u msecs", msecs)); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_decline(): set request timeout %u msecs", msecs)); return result; } #endif @@ -643,7 +650,7 @@ static err_t dhcp_discover(struct netif *netif) struct dhcp *dhcp = netif->dhcp; err_t result = ERR_OK; u16_t msecs; - DEBUGF(DHCP_DEBUG, ("dhcp_discover()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_discover()")); ip_addr_set(&dhcp->offered_ip_addr, IP_ADDR_ANY); /* create and initialize the DHCP message header */ result = dhcp_create_request(netif); @@ -677,7 +684,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, ("dhcp_discover(): set request timeout %u msecs", msecs)); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_discover(): set request timeout %u msecs", msecs)); dhcp_set_state(dhcp, DHCP_SELECTING); return result; } @@ -696,17 +703,17 @@ static void dhcp_bind(struct netif *netif) /* temporary DHCP lease? */ if (dhcp->offered_t1_renew != 0xffffffffUL) { /* set renewal period timer */ - DEBUGF(DHCP_DEBUG, ("dhcp_bind(): t1 renewal timer %lu secs", dhcp->offered_t1_renew)); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t1 renewal timer %lu secs", 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, ("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", dhcp->offered_t1_renew*1000)); } /* set renewal period timer */ if (dhcp->offered_t2_rebind != 0xffffffffUL) { - DEBUGF(DHCP_DEBUG, ("dhcp_bind(): t2 rebind timer %lu secs", dhcp->offered_t2_rebind)); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_bind(): t2 rebind timer %lu secs", 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, ("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", dhcp->offered_t2_rebind*1000)); } /* copy offered network mask */ ip_addr_set(&sn_mask, &dhcp->offered_sn_mask); @@ -730,11 +737,11 @@ static void dhcp_bind(struct netif *netif) gw_addr.addr |= htonl(0x00000001); } - DEBUGF(DHCP_DEBUG, ("dhcp_bind(): IP: 0x%08lx", dhcp->offered_ip_addr.addr)); + DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): IP: 0x%08lx", dhcp->offered_ip_addr.addr)); netif_set_ipaddr(netif, &dhcp->offered_ip_addr); - DEBUGF(DHCP_DEBUG, ("dhcp_bind(): SN: 0x%08lx", sn_mask.addr)); + DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): SN: 0x%08lx", sn_mask.addr)); netif_set_netmask(netif, &sn_mask); - DEBUGF(DHCP_DEBUG, ("dhcp_bind(): GW: 0x%08lx", gw_addr.addr)); + DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_bind(): GW: 0x%08lx", gw_addr.addr)); netif_set_gw(netif, &gw_addr); /* netif is now bound to DHCP leased address */ dhcp_set_state(dhcp, DHCP_BOUND); @@ -750,7 +757,7 @@ err_t dhcp_renew(struct netif *netif) struct dhcp *dhcp = netif->dhcp; err_t result; u16_t msecs; - DEBUGF(DHCP_DEBUG, ("dhcp_renew()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_renew()")); dhcp_set_state(dhcp, DHCP_RENEWING); /* create and initialize the DHCP message header */ @@ -787,7 +794,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, ("dhcp_renew(): set request timeout %u msecs", msecs)); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_renew(): set request timeout %u msecs", msecs)); return result; } @@ -801,7 +808,7 @@ static err_t dhcp_rebind(struct netif *netif) struct dhcp *dhcp = netif->dhcp; err_t result; u16_t msecs; - DEBUGF(DHCP_DEBUG, ("dhcp_rebind()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind()")); dhcp_set_state(dhcp, DHCP_REBINDING); /* create and initialize the DHCP message header */ @@ -836,7 +843,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, ("dhcp_rebind(): set request timeout %u msecs", msecs)); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_rebind(): set request timeout %u msecs", msecs)); return result; } @@ -850,7 +857,7 @@ static err_t dhcp_release(struct netif *netif) struct dhcp *dhcp = netif->dhcp; err_t result; u16_t msecs; - DEBUGF(DHCP_DEBUG, ("dhcp_release()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_release()")); /* idle DHCP client */ dhcp_set_state(dhcp, DHCP_OFF); @@ -872,7 +879,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, ("dhcp_release(): set request timeout %u msecs", msecs)); + DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_release(): set request timeout %u msecs", msecs)); /* remove IP address from interface */ netif_set_ipaddr(netif, IP_ADDR_ANY); netif_set_gw(netif, IP_ADDR_ANY); @@ -888,7 +895,7 @@ static err_t dhcp_release(struct netif *netif) void dhcp_stop(struct netif *netif) { struct dhcp *dhcp = netif->dhcp; - DEBUGF(DHCP_DEBUG, ("dhcp_stop()")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_stop()")); /* netif is DHCP configured? */ if (dhcp != NULL) { @@ -987,14 +994,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, ("dhcp_unfold_reply(): could not allocate dhcp->options")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->options")); return ERR_MEM; } } dhcp->msg_in = mem_malloc(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN); if (dhcp->msg_in == NULL) { - DEBUGF(DHCP_DEBUG, ("dhcp_unfold_reply(): could not allocate dhcp->msg_in")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_unfold_reply(): could not allocate dhcp->msg_in")); mem_free((void *)dhcp->options_in); dhcp->options_in = NULL; return ERR_MEM; @@ -1013,7 +1020,7 @@ static err_t dhcp_unfold_reply(struct dhcp *dhcp) j = 0; } } - DEBUGF(DHCP_DEBUG, ("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[]", i)); if (dhcp->options_in != NULL) { ptr = (u8_t *)dhcp->options_in; /* proceed through options */ @@ -1026,7 +1033,7 @@ static err_t dhcp_unfold_reply(struct dhcp *dhcp) j = 0; } } - DEBUGF(DHCP_DEBUG, ("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[]", i)); } return ERR_OK; } @@ -1062,18 +1069,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, ("dhcp_recv()")); - DEBUGF(DHCP_DEBUG, ("pbuf->len = %u", p->len)); - DEBUGF(DHCP_DEBUG, ("pbuf->tot_len = %u", p->tot_len)); + 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)); dhcp->p = p; if (reply_msg->op != DHCP_BOOTREPLY) { - DEBUGF(DHCP_DEBUG, ("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", 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, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x", + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("netif->hwaddr[%u]==%02x != reply_msg->chaddr[%u]==%02x", i, netif->hwaddr[i], i, reply_msg->chaddr[i])); pbuf_free(p); return; @@ -1081,22 +1088,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, ("transaction id mismatch")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("transaction id mismatch")); pbuf_free(p); return; } /* option fields could be unfold? */ if (dhcp_unfold_reply(dhcp) != ERR_OK) { - DEBUGF(DHCP_DEBUG, ("problem unfolding DHCP message - too short on memory?")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("problem unfolding DHCP message - too short on memory?")); pbuf_free(p); return; } - DEBUGF(DHCP_DEBUG, ("searching DHCP_OPTION_MESSAGE_TYPE")); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE")); /* obtain pointer to DHCP message type */ options_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_MESSAGE_TYPE); if (options_ptr == NULL) { - DEBUGF(DHCP_DEBUG, ("DHCP_OPTION_MESSAGE_TYPE option not found")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OPTION_MESSAGE_TYPE option not found")); pbuf_free(p); return; } @@ -1105,7 +1112,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, ("DHCP_ACK received")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_ACK received")); /* in requesting state? */ if (dhcp->state == DHCP_REQUESTING) { dhcp_handle_ack(netif); @@ -1128,13 +1135,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, ("DHCP_NAK received")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_NAK received")); 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, ("DHCP_OFFER received in DHCP_SELECTING state")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("DHCP_OFFER received in DHCP_SELECTING state")); dhcp->request_timeout = 0; /* remember offered lease */ dhcp_handle_offer(netif); @@ -1151,7 +1158,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, ("dhcp_create_request(): could not allocate pbuf")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_create_request(): could not allocate pbuf")); return ERR_MEM; } /* give unique transaction identifier to this request */ @@ -1239,14 +1246,14 @@ 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, ("overloaded message detected")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("overloaded message detected")); /* skip option type and length */ offset += 2; overload = options[offset++]; } /* requested option found */ else if (options[offset] == option_type) { - DEBUGF(DHCP_DEBUG, ("option found at offset %u in options", offset)); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset %u in options", offset)); return &options[offset]; /* skip option */ } else { @@ -1261,16 +1268,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, ("overloaded file field")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded file field")); options = (u8_t *)&dhcp->msg_in->file; field_len = DHCP_FILE_LEN; } else if (overload == DHCP_OVERLOAD_SNAME) { - DEBUGF(DHCP_DEBUG, ("overloaded sname field")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname field")); options = (u8_t *)&dhcp->msg_in->sname; field_len = DHCP_SNAME_LEN; /* TODO: check if else if () is necessary */ } else { - DEBUGF(DHCP_DEBUG, ("overloaded sname and file field")); + DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("overloaded sname and file field")); options = (u8_t *)&dhcp->msg_in->sname; field_len = DHCP_FILE_LEN + DHCP_SNAME_LEN; } @@ -1279,11 +1286,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, ("option found at offset=%u", offset)); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("option found at offset=%u", offset)); return &options[offset]; /* skip option */ } else { - DEBUGF(DHCP_DEBUG, ("skipping option %u", options[offset])); + DEBUGF(DHCP_DEBUG | DBG_TRACE, ("skipping option %u", options[offset])); /* skip option type */ offset++; offset += 1 + options[offset]; diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index 88e3da57..c6e83614 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -236,7 +236,7 @@ ip_input(struct pbuf *p, struct netif *inp) { /* identify the IP header */ iphdr = p->payload; if(IPH_V(iphdr) != 4) { - DEBUGF(IP_DEBUG, ("IP packet dropped due to bad version number %d\n", IPH_V(iphdr))); + DEBUGF(IP_DEBUG | 1, ("IP packet dropped due to bad version number %d\n", IPH_V(iphdr))); #if IP_DEBUG ip_debug_print(p); #endif /* IP_DEBUG */ @@ -255,7 +255,7 @@ ip_input(struct pbuf *p, struct netif *inp) { /* header length exceeds first pbuf length? */ if(iphdrlen > p->len) { - DEBUGF(IP_DEBUG, ("IP header (len %u) does not fit in first pbuf (len %u), IP packet droppped.\n", + DEBUGF(IP_DEBUG | 2, ("IP header (len %u) does not fit in first pbuf (len %u), IP packet droppped.\n", iphdrlen, p->len)); /* free (drop) packet pbufs */ pbuf_free(p); @@ -270,7 +270,7 @@ ip_input(struct pbuf *p, struct netif *inp) { /* verify checksum */ if(inet_chksum(iphdr, iphdrlen) != 0) { - DEBUGF(IP_DEBUG, ("Checksum (0x%x) failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen))); + DEBUGF(IP_DEBUG | 2, ("Checksum (0x%x) failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen))); #if IP_DEBUG ip_debug_print(p); #endif /* IP_DEBUG */ @@ -320,10 +320,10 @@ ip_input(struct pbuf *p, struct netif *inp) { if(netif == NULL) { /* remote port is DHCP server? */ if(IPH_PROTO(iphdr) == IP_PROTO_UDP) { - DEBUGF(IP_DEBUG, ("ip_input: UDP packet to DHCP client port %u\n", + 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))); if (ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest) == DHCP_CLIENT_PORT) { - DEBUGF(IP_DEBUG, ("ip_input: DHCP packet accepted.\n")); + DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: DHCP packet accepted.\n")); netif = inp; } } @@ -332,7 +332,7 @@ ip_input(struct pbuf *p, struct netif *inp) { /* packet not for us? */ if(netif == NULL) { /* packet not for us, route or discard */ - DEBUGF(IP_DEBUG, ("ip_input: packet not for us.\n")); + DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: packet not for us.\n")); #if IP_FORWARD /* non-broadcast packet? */ if(!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) { @@ -360,7 +360,7 @@ ip_input(struct pbuf *p, struct netif *inp) { #else /* IP_REASSEMBLY */ if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { pbuf_free(p); - DEBUGF(IP_DEBUG, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n", + DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n", ntohs(IPH_OFFSET(iphdr)))); #ifdef IP_STATS ++lwip_stats.ip.opterr; @@ -372,8 +372,8 @@ ip_input(struct pbuf *p, struct netif *inp) { #endif /* IP_REASSEMBLY */ #if IP_OPTIONS == 0 - if(iphdrlen > IP_HLEN) { - DEBUGF(IP_DEBUG, ("IP packet dropped since there were IP options (while IP_OPTIONS == 0).\n")); + if (iphdrlen > IP_HLEN) { + DEBUGF(IP_DEBUG | 2, ("IP packet dropped since there were IP options (while IP_OPTIONS == 0).\n")); pbuf_free(p); #ifdef IP_STATS ++lwip_stats.ip.opterr; @@ -417,7 +417,7 @@ ip_input(struct pbuf *p, struct netif *inp) { } pbuf_free(p); - DEBUGF(IP_DEBUG, ("Unsupported transportation protocol %d\n", IPH_PROTO(iphdr))); + DEBUGF(IP_DEBUG | 2, ("Unsupported transport protocol %d\n", IPH_PROTO(iphdr))); #ifdef IP_STATS ++lwip_stats.ip.proterr; @@ -450,7 +450,7 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, if(dest != IP_HDRINCL) { if(pbuf_header(p, IP_HLEN)) { - DEBUGF(IP_DEBUG, ("ip_output: not enough room for IP header in pbuf\n")); + DEBUGF(IP_DEBUG | 2, ("ip_output: not enough room for IP header in pbuf\n")); #ifdef IP_STATS ++lwip_stats.ip.err; @@ -517,7 +517,7 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, struct netif *netif; if((netif = ip_route(dest)) == NULL) { - DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%lx\n", dest->addr)); + DEBUGF(IP_DEBUG | 2, ("ip_output: No route to 0x%lx\n", dest->addr)); #ifdef IP_STATS ++lwip_stats.ip.rterr; diff --git a/src/core/netif.c b/src/core/netif.c index cdcb65a7..bb4b9fef 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -1,3 +1,9 @@ +/** + * @file + * + * lwIP network interface abstraction + */ + /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. * All rights reserved. @@ -132,8 +138,9 @@ void netif_remove(struct netif * netif) if(tmpNetif == NULL) return; /* we didn't find any netif today */ } - - if(netif_default == netif) + /* this netif is default? */ + if (netif_default == netif) + /* reset default netif */ netif_default = NULL; DEBUGF(NETIF_DEBUG, ("netif_remove: removed netif")); diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 84c409a0..9518d1e6 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -1,3 +1,7 @@ +/** + * @file + * Packet buffers/chains management module + */ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. * All rights reserved. @@ -88,7 +92,7 @@ pbuf_init(void) lwip_stats.pbuf.avail = PBUF_POOL_SIZE; #endif /* PBUF_STATS */ - /* Set up ->next pointers to link the pbufs of the pool together. */ + /* Set up ->next pointers to link the pbufs of the pool together */ p = pbuf_pool; for(i = 0; i < PBUF_POOL_SIZE; ++i) { @@ -100,7 +104,7 @@ pbuf_init(void) } /* The ->next pointer of last pbuf is NULL to indicate that there - are no more pbufs in the pool. */ + are no more pbufs in the pool */ q->next = NULL; #if !SYS_LIGHTWEIGHT_PROT @@ -219,6 +223,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag) u16_t offset; s32_t rsize; + /* determine header offset */ offset = 0; switch(l) { case PBUF_TRANSPORT: @@ -239,7 +244,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag) switch(flag) { case PBUF_POOL: - /* Allocate head of pbuf chain into p. */ + /* allocate head of pbuf chain into p */ p = pbuf_pool_alloc(); if(p == NULL) { #ifdef PBUF_STATS @@ -249,19 +254,18 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag) } p->next = NULL; - /* Set the payload pointer so that it points offset bytes into - pbuf data memory. */ + /* make the payload pointer points 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. */ + /* the total length of the pbuf is the requested size */ p->tot_len = size; - /* Set the length of the first pbuf is the chain. */ + /* set the length of the first pbuf is the chain */ p->len = size > PBUF_POOL_BUFSIZE - offset? PBUF_POOL_BUFSIZE - offset: size; p->flags = PBUF_FLAG_POOL; - /* Allocate the tail of the pbuf chain. */ + /* allocate the tail of the pbuf chain. */ r = p; rsize = size - p->len; while(rsize > 0) { @@ -304,7 +308,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag) LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned", ((u32_t)p->payload % MEM_ALIGNMENT) == 0); break; - /* pbuf references existing ROM payload? */ + /* pbuf references existing (static constant) ROM payload? */ case PBUF_ROM: /* pbuf references existing (externally allocated) RAM payload? */ case PBUF_REF: @@ -318,10 +322,7 @@ pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag) p->payload = NULL; p->len = p->tot_len = size; p->next = NULL; - if (flag == PBUF_ROM) - p->flags = PBUF_FLAG_ROM; - else - p->flags = PBUF_FLAG_REF; + p->flags = (flag == PBUF_ROM? PBUF_FLAG_ROM: PBUF_FLAG_REF); break; default: LWIP_ASSERT("pbuf_alloc: erroneous flag", 0); @@ -426,7 +427,6 @@ pbuf_realloc(struct pbuf *p, u16_t size) p->flags == PBUF_FLAG_RAM || p->flags == PBUF_FLAG_REF); - if(p->tot_len <= size) { return; } @@ -487,23 +487,25 @@ pbuf_realloc(struct pbuf *p, u16_t size) pbuf_refresh(); } -/*-----------------------------------------------------------------------------------*/ -/* pbuf_header(): - * +/** + * Decreases the header size by the given amount. + * * Adjusts the ->payload pointer so that space for a header appears in * the pbuf. Also, the ->tot_len and ->len fields are adjusted. * - * Decreases the header size by the given amount. - * Using a negative value increases the header size. + * @param hdr_decrement Number of bytes to decrement header size. + * (Using a negative value increases the header size.) + * + * @return 1 on failure, 0 on succes. */ /*-----------------------------------------------------------------------------------*/ u8_t pbuf_header(struct pbuf *p, s16_t header_size) { void *payload; - - if(p->flags == PBUF_FLAG_ROM || - p->flags == PBUF_FLAG_REF) { + /* referencing pbufs cannot be realloc()ed */ + if (p->flags == PBUF_FLAG_ROM || + p->flags == PBUF_FLAG_REF) { return 1; } @@ -512,10 +514,12 @@ pbuf_header(struct pbuf *p, s16_t 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 %p %p\n", + DEBUGF(PBUF_DEBUG | 2, ("pbuf_header: failed as %p < %p\n", (u8_t *)p->payload, - (u8_t *)p + sizeof(struct pbuf))); + (u8_t *)p + sizeof(struct pbuf)));\ + /* restore old payload pointer */ p->payload = payload; return 1; } @@ -539,7 +543,8 @@ pbuf_free(struct pbuf *p) u8_t count = 0; SYS_ARCH_DECL_PROTECT(old_level); - if(p == NULL) { + if (p == NULL) { + DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_free(p==NULL) was called.\n")); return 0; } @@ -551,43 +556,39 @@ pbuf_free(struct pbuf *p) p->flags == PBUF_FLAG_REF ); /* Since decrementing ref cannot be guarranteed to be a single machine operation - we must protect it. Also, the later test of ref must be protected. - */ + * we must protect it. Also, the later test of ref must be protected. + */ SYS_ARCH_PROTECT(old_level); - /* Decrement reference count. */ + /* decrement individual reference count for each pbufs in chain */ for (q = p; q != NULL; q = q->next) { LWIP_ASSERT("pbuf_free: q->ref > 0", q->ref > 0); q->ref--; - } + } - /* If reference count == 0, actually deallocate pbuf. */ - if(p->ref == 0) { - SYS_ARCH_UNPROTECT(old_level); + /* if reference count == 0, actually deallocate pbuf */ + if (p->ref == 0) { + SYS_ARCH_UNPROTECT(old_level); - while(p != NULL) { + while (p != NULL) { + /* remember next in chain */ + q = p->next; /* this is a pbuf from the pool? */ - if(p->flags == PBUF_FLAG_POOL) { + if (p->flags == PBUF_FLAG_POOL) { p->len = p->tot_len = PBUF_POOL_BUFSIZE; p->payload = (void *)((u8_t *)p + sizeof(struct pbuf)); - q = p->next; PBUF_POOL_FREE(p); - /* not a pbuf from the pool */ + /* RAM/ROM referencing pbuf */ + } else if (p->flags == PBUF_FLAG_ROM || p->flags == PBUF_FLAG_REF) { + memp_freep(MEMP_PBUF, p); + /* pbuf with data */ + } else { + mem_free(p); } - else { - if(p->flags == PBUF_FLAG_ROM || p->flags == PBUF_FLAG_REF) { - q = p->next; - memp_freep(MEMP_PBUF, p); - } - else { - q = p->next; - mem_free(p); - } - } - + /* next in chain */ p = q; /* Only free the next one in a chain if it's reference count is 0. This allows buffer chains to have multiple headers pointing to them. */ - if (p) + if (p != NULL) { p->ref--; if (p->ref > 0) @@ -597,10 +598,8 @@ pbuf_free(struct pbuf *p) ++count; } pbuf_refresh(); - } - else - SYS_ARCH_UNPROTECT(old_level); - + } else + SYS_ARCH_UNPROTECT(old_level); PERF_STOP("pbuf_free"); return count; @@ -682,22 +681,26 @@ pbuf_chain(struct pbuf *h, struct pbuf *t) p->next = t; h->tot_len += t->tot_len; } -/*-----------------------------------------------------------------------------------*/ -/* pbuf_dechain(): + +/** + * Dechains a pbuf from any succeeding pbufs in the chain. * - * Adjusts the ->tot_len field of the pbuf and returns the tail (if - * any) of the pbuf chain. + * Makes p->tot_len field equal to p->len. + * @param p pbuf to dechain + * @return remainder (if any) of the pbuf chain. */ -/*-----------------------------------------------------------------------------------*/ struct pbuf * pbuf_dechain(struct pbuf *p) { struct pbuf *q; q = p->next; + /* pbuf has successor in chain? */ if (q != NULL) { + /* LW: shouldn't q->tot_len be already exactly this? (make this an assert?) */ q->tot_len = p->tot_len - p->len; } + /* decouple pbuf from remainder */ p->tot_len = p->len; p->next = NULL; return q; diff --git a/src/core/tcp.c b/src/core/tcp.c index 5f159b40..1f9c5f48 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1,3 +1,9 @@ +/** + * @file + * + * Transmission Control Protocol for IP + */ + /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. * All rights reserved. diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 5c38ab1f..dafe949a 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -1,3 +1,9 @@ +/** + * @file + * + * Transmission Control Protocol, incoming traffic + */ + /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. * All rights reserved. diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 7a8cfd0a..3fe76438 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1,3 +1,8 @@ +/** + * @file + * + * Transmission Control Protocol, outgoing traffic + */ /* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. * All rights reserved. diff --git a/src/include/lwip/debug.h b/src/include/lwip/debug.h index a48decf9..f066d3d8 100644 --- a/src/include/lwip/debug.h +++ b/src/include/lwip/debug.h @@ -42,9 +42,9 @@ */ #define DBG_LEVEL_OFF 0 -#define DBG_LEVEL_WARNING 1 -#define DBG_LEVEL_SERIOUS 2 -#define DBG_LEVEL_SEVERE 3 +#define DBG_LEVEL_WARNING 1 /* bad checksums, dropped packets, ... */ +#define DBG_LEVEL_SERIOUS 2 /* memory allocation failures, ... */ +#define DBG_LEVEL_SEVERE 3 /* */ #define DBG_MASK_LEVEL 3 /** flag for DEBUGF to enable the debug message */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 9f0660bd..1b56cf2d 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -174,7 +174,7 @@ a lot of data that needs to be copied, this should be set high. */ IP packets across network interfaces. If you are going to run lwIP on a device with only one network interface, define this to 0. */ #ifndef IP_FORWARD -#define IP_FORWARD 1 +#define IP_FORWARD 0 #endif /* If defined to 1, IP options are allowed (but not parsed). If diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 85841011..cbd4d89c 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -650,12 +650,12 @@ struct pbuf *etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pb for(i = 0; i < ARP_TABLE_SIZE; ++i) { if(ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { if (arp_table[i].state == ETHARP_STATE_PENDING) { - DEBUGF(ETHARP_DEBUG, ("etharp_query: requested IP already pending\n")); + DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: requested IP already pending as entry %u\n", i)); /* break out of for-loop */ break; } else if (arp_table[i].state == ETHARP_STATE_STABLE) { - DEBUGF(ETHARP_DEBUG, ("etharp_query: requested IP already stable\n")); + DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: requested IP already stable as entry %u\n", i)); return NULL; } } @@ -663,16 +663,16 @@ struct pbuf *etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pb /* queried address not yet pending in ARP table? */ if (i == ARP_TABLE_SIZE) { - DEBUGF(ETHARP_DEBUG, ("etharp_query: IP address non-pending\n")); + DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_query: IP address not found in ARP table\n")); /* find an available entry */ i = find_arp_entry(); /* bail out if no ARP entries are available */ if(i == ARP_TABLE_SIZE) { - DEBUGF(ETHARP_DEBUG, ("etharp_query: no more ARP table entries available.\n")); + DEBUGF(ETHARP_DEBUG | 2, ("etharp_query: no more ARP entries available.\n")); return NULL; } - DEBUGF(ETHARP_DEBUG, ("etharp_query: created ARP table entry.\n")); + DEBUGF(ETHARP_DEBUG, ("etharp_query: created ARP table entry %u.\n", i)); /* i is available, create ARP entry */ ip_addr_set(&arp_table[i].ipaddr, ipaddr); arp_table[i].ctime = 0; @@ -690,7 +690,7 @@ struct pbuf *etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pb pbuf_ref_chain(q); /* remember pbuf to queue, if any */ arp_table[i].p = q; - DEBUGF(ETHARP_DEBUG, ("etharp_query: queued packet on ARP entry.\n")); + DEBUGF(ETHARP_DEBUG, ("etharp_query: queued packet %p on ARP entry %u.\n", (void *)q, i)); } #endif /* allocate a pbuf for the outgoing ARP request packet */