Added assertions where PBUF_RAM pbufs are used and an assumption is made that this pbuf is in one piece (i.e. not chained). These assumptions clash with the possibility of converting to fully pool-based pbuf implementations, where PBUF_RAM pbufs might be chained.

This commit is contained in:
goldsimon
2007-07-03 20:28:35 +00:00
parent 2a77b9fcc7
commit eb875de67e
13 changed files with 86 additions and 15 deletions

View File

@@ -112,6 +112,8 @@ icmp_input(struct pbuf *p, struct netif *inp)
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: allocating new pbuf failed\n"));
goto memerr;
}
LWIP_ASSERT("check that first pbuf can hold struct the ICMP header",
(r->len >= hlen + sizeof(struct icmp_echo_hdr)));
/* copy the whole packet including ip header */
if (pbuf_copy(r, p) != ERR_OK) {
LWIP_ASSERT("icmp_input: copying to new pbuf failed\n", 0);
@@ -201,8 +203,16 @@ icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t)
struct ip_hdr *iphdr;
struct icmp_dur_hdr *idur;
/* @todo: can this be PBUF_LINK instead of PBUF_IP? */
q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM);
/* ICMP header + IP header + 8 bytes of data */
if (q == NULL) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_dest_unreach: failed to allocate pbuf for ICMP packet.\n"));
pbuf_free(p);
return;
}
LWIP_ASSERT("check that first pbuf can hold icmp message",
(q->len >= (8 + IP_HLEN + 8)));
iphdr = p->payload;
@@ -240,7 +250,16 @@ icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t)
struct ip_hdr *iphdr;
struct icmp_te_hdr *tehdr;
/* @todo: can this be PBUF_LINK instead of PBUF_IP? */
q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM);
/* ICMP header + IP header + 8 bytes of data */
if (q == NULL) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded: failed to allocate pbuf for ICMP packet.\n"));
pbuf_free(p);
return;
}
LWIP_ASSERT("check that first pbuf can hold icmp message",
(q->len >= (8 + IP_HLEN + 8)));
iphdr = p->payload;
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded from "));

View File

@@ -562,6 +562,8 @@ igmp_send(struct igmp_group *group, u8_t type)
if (p) {
igmp = p->payload;
LWIP_ASSERT("check that first pbuf can hold struct igmpmsg",
(p->len >= sizeof(struct igmpmsg)));
ip_addr_set(&src, &((group->interface)->ip_addr));
if (IGMP_V2_MEMB_REPORT == type) {

View File

@@ -460,6 +460,8 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
}
iphdr = p->payload;
LWIP_ASSERT("check that first pbuf can hold struct ip_hdr",
(p->len >= sizeof(struct ip_hdr)));
IPH_TTL_SET(iphdr, ttl);
IPH_PROTO_SET(iphdr, proto);

View File

@@ -403,6 +403,8 @@ ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest)
if (rambuf == NULL) {
return ERR_MEM;
}
LWIP_ASSERT("this needs a pbuf in one piece!",
(p->len >= (IP_HLEN)));
SMEMCPY(rambuf->payload, original_iphdr, IP_HLEN);
iphdr = rambuf->payload;