Applied patches posted by Marc Boucher on lwip-users May 18th 2003.

This commit is contained in:
likewise 2003-05-18 22:29:10 +00:00
parent 24a9063721
commit cda867d52b
6 changed files with 38 additions and 24 deletions

View File

@ -1105,7 +1105,7 @@ static void dhcp_free_reply(struct dhcp *dhcp)
/** /**
* If an incoming DHCP message is in response to use, then trigger the state machine * If an incoming DHCP message is in response to us, then trigger the state machine
*/ */
static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port) static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{ {
@ -1116,15 +1116,14 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_
u8_t msg_type; u8_t msg_type;
u8_t i; u8_t i;
DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_recv(pbuf = %p) from DHCP server %u.%u.%u.%u port %u\n", p, DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_recv(pbuf = %p) from DHCP server %u.%u.%u.%u port %u\n", p,
(u8_t)(ntohl(addr->addr) >> 24 & 0xff), (u8_t)(ntohl(addr->addr) >> 24 & 0xff), (u8_t)(ntohl(addr->addr) >> 16 & 0xff),
(u8_t)(ntohl(addr->addr) >> 16 & 0xff), (u8_t)(ntohl(addr->addr) >> 8 & 0xff), (u8_t)(ntohl(addr->addr) & 0xff), port));
(u8_t)(ntohl(addr->addr) >> 8 & 0xff),
(u8_t)(ntohl(addr->addr) & 0xff), port));
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %u\n", p->len)); DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->len = %u\n", p->len));
DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %u\n", p->tot_len)); DEBUGF(DHCP_DEBUG | DBG_TRACE, ("pbuf->tot_len = %u\n", p->tot_len));
/* prevent warning */ /* prevent warnings about unused arguments */
if (pcb || addr || port); (void)pcb; (void)addr; (void)port;
dhcp->p = p; dhcp->p = p;
/* TODO: check packet length before reading them */
if (reply_msg->op != DHCP_BOOTREPLY) { if (reply_msg->op != DHCP_BOOTREPLY) {
DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("not a DHCP reply message, but type %u\n", reply_msg->op)); DEBUGF(DHCP_DEBUG | DBG_TRACE | 1, ("not a DHCP reply message, but type %u\n", reply_msg->op));
pbuf_free(p); pbuf_free(p);

View File

@ -51,11 +51,12 @@ icmp_input(struct pbuf *p, struct netif *inp)
struct ip_hdr *iphdr; struct ip_hdr *iphdr;
struct ip_addr tmpaddr; struct ip_addr tmpaddr;
#ifdef ICMP_STATS #ifdef ICMP_STATS
++lwip_stats.icmp.recv; ++lwip_stats.icmp.recv;
#endif /* ICMP_STATS */ #endif /* ICMP_STATS */
/* TODO: check length before accessing payload! */
type = ((char *)p->payload)[0]; type = ((char *)p->payload)[0];
switch (type) { switch (type) {
@ -103,8 +104,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
iphdr->hoplim, IP_PROTO_ICMP, inp); iphdr->hoplim, IP_PROTO_ICMP, inp);
break; break;
default: default:
DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type not supported.\n")); DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %d not supported.\n", (int)type));
#ifdef ICMP_STATS #ifdef ICMP_STATS
++lwip_stats.icmp.proterr; ++lwip_stats.icmp.proterr;
++lwip_stats.icmp.drop; ++lwip_stats.icmp.drop;

View File

@ -10,13 +10,14 @@
* A packet may span over multiple pbufs, chained as a singly linked * A packet may span over multiple pbufs, chained as a singly linked
* list. This is called a "pbuf chain". * list. This is called a "pbuf chain".
* *
* Multiple packets may be queued using this singly linked list. This * Multiple packets may be queued, also using this singly linked list.
* is called a "pbuf queue". So, a pbuf queue consists of one or more * This is called a "packet queue". So, a packet queue consists of one
* pbuf chains, each of which consist of one or more pbufs. * or more pbuf chains, each of which consist of one or more pbufs.
* *
* In order to find the last pbuf of a packet, traverse the linked list * The last pbuf of a packet has a ->tot_len field that equals the
* until the ->tot_len field equals the ->len field. If the ->next field * ->len field. It can be found by traversing the list. If the last
* of this packet is not NULL, more packets are on the queue. * pbuf of a packet has a ->next field other than NULL, more packets
* are on the queue.
*/ */
/* /*
@ -366,6 +367,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
* resized, and any remaining pbufs will be freed. * resized, and any remaining pbufs will be freed.
* *
* @note If the pbuf is ROM/REF, only the ->tot_len and ->len fields are adjusted. * @note If the pbuf is ROM/REF, only the ->tot_len and ->len fields are adjusted.
* @note May not be called on a packet queue.
* *
* @bug Cannot grow the size of a pbuf (chain) (yet). * @bug Cannot grow the size of a pbuf (chain) (yet).
*/ */
@ -442,6 +444,8 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
* the call will fail. A check is made that the increase in header size does * the call will fail. A check is made that the increase in header size does
* not move the payload pointer in front of the start of the buffer. * not move the payload pointer in front of the start of the buffer.
* @return 1 on failure, 0 on success. * @return 1 on failure, 0 on success.
*
* @note May not be called on a packet queue.
*/ */
u8_t u8_t
pbuf_header(struct pbuf *p, s16_t header_size) pbuf_header(struct pbuf *p, s16_t header_size)
@ -500,6 +504,7 @@ pbuf_header(struct pbuf *p, s16_t header_size)
* @return the number of unreferenced pbufs that were de-allocated * @return the number of unreferenced pbufs that were de-allocated
* from the head of the chain. * from the head of the chain.
* *
* @note May not be called on a packet queue.
* @note the reference counter of a pbuf equals the number of pointers * @note the reference counter of a pbuf equals the number of pointers
* that refer to the pbuf (or into the pbuf). * that refer to the pbuf (or into the pbuf).
* *
@ -593,6 +598,7 @@ pbuf_clen(struct pbuf *p)
} }
return len; return len;
} }
/** /**
* *
* Increment the reference count of the pbuf. * Increment the reference count of the pbuf.
@ -618,6 +624,7 @@ pbuf_ref(struct pbuf *p)
* *
* @param h head pbuf (chain) * @param h head pbuf (chain)
* @param t tail pbuf (chain) * @param t tail pbuf (chain)
* @note May not be called on a packet queue.
* *
* The ->tot_len fields of all pbufs of the head chain are adjusted. * The ->tot_len fields of all pbufs of the head chain are adjusted.
* The ->next field of the last pbuf of the head chain is adjusted. * The ->next field of the last pbuf of the head chain is adjusted.
@ -651,8 +658,9 @@ pbuf_chain(struct pbuf *h, struct pbuf *t)
DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_chain: referencing tail %p\n", (void *) t)); DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_chain: referencing tail %p\n", (void *) t));
} }
/* TODO: Will be enabled soon. Please review code. */ /* For packet queueing. Note that queued packets must be dequeued first
#if 1 * before calling any pbuf functions. */
#if ARP_QUEUEING
/** /**
* Add a packet to the end of a queue. * Add a packet to the end of a queue.
* *
@ -680,6 +688,8 @@ pbuf_queue(struct pbuf *p, struct pbuf *n)
p = p->next; p = p->next;
} }
#endif #endif
/* now p->tot_len == p->len */
/* proceed to next packet on queue */
p = p->next; p = p->next;
} }
/* chain last pbuf of h chain (p) with first of tail (t) */ /* chain last pbuf of h chain (p) with first of tail (t) */
@ -714,7 +724,7 @@ pbuf_dequeue(struct pbuf *p)
p->next = NULL; p->next = NULL;
/* q is now referenced to one less time */ /* q is now referenced to one less time */
pbuf_free(q); pbuf_free(q);
DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_dequeue: dereferencing remaining queue%p\n", (void *)q)); DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_dequeue: dereferencing remaining queue %p\n", (void *)q));
return q; return q;
} }
#endif #endif
@ -831,6 +841,7 @@ pbuf_take(struct pbuf *p)
* Makes p->tot_len field equal to p->len. * Makes p->tot_len field equal to p->len.
* @param p pbuf to dechain * @param p pbuf to dechain
* @return remainder of the pbuf chain, or NULL if it was de-allocated. * @return remainder of the pbuf chain, or NULL if it was de-allocated.
* @note May not be called on a packet queue.
*/ */
struct pbuf * struct pbuf *
pbuf_dechain(struct pbuf *p) pbuf_dechain(struct pbuf *p)

View File

@ -113,7 +113,8 @@ tcp_input(struct pbuf *p, struct netif *inp)
iphdr = p->payload; iphdr = p->payload;
tcphdr = (struct tcp_hdr *)((u8_t *)p->payload + IPH_HL(iphdr) * 4); tcphdr = (struct tcp_hdr *)((u8_t *)p->payload + IPH_HL(iphdr) * 4);
if (pbuf_header(p, -((s16_t)(IPH_HL(iphdr) * 4)))) { /* remove header from payload */
if (pbuf_header(p, -((s16_t)(IPH_HL(iphdr) * 4))) || (p->tot_len < sizeof(struct tcp_hdr))) {
/* drop short packets */ /* drop short packets */
DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: short packet (%u bytes) discarded\n", p->tot_len)); DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: short packet (%u bytes) discarded\n", p->tot_len));
#ifdef TCP_STATS #ifdef TCP_STATS

View File

@ -49,9 +49,9 @@ void mem_free(void *mem);
void *mem_realloc(void *mem, mem_size_t size); void *mem_realloc(void *mem, mem_size_t size);
void *mem_reallocm(void *mem, mem_size_t size); void *mem_reallocm(void *mem, mem_size_t size);
#define MEM_ALIGN_SIZE(size) ((size + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1)) #define MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
#define MEM_ALIGN(addr) (void *)MEM_ALIGN_SIZE((mem_ptr_t)addr) #define MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
#endif /* __LWIP_MEM_H__ */ #endif /* __LWIP_MEM_H__ */

View File

@ -72,7 +72,10 @@ struct pbuf {
/** /**
* total length of this buffer and all next buffers in chain * total length of this buffer and all next buffers in chain
* invariant: p->tot_len == p->len + (p->next? p->next->tot_len: 0) * belonging to the same packet.
*
* For non-queue packet chains this is the invariant:
* p->tot_len == p->len + (p->next? p->next->tot_len: 0)
*/ */
u16_t tot_len; u16_t tot_len;