mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-11 10:03:47 +08:00
task #14597: cleanup pbuf_header usages (use pbuf_add_header/pbuf_remove_header instead)
This commit is contained in:
@@ -152,7 +152,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
|
||||
}
|
||||
#endif
|
||||
#if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
|
||||
if (pbuf_header(p, (s16_t)(hlen + PBUF_LINK_HLEN + PBUF_LINK_ENCAPSULATION_HLEN))) {
|
||||
if (pbuf_add_header(p, hlen + PBUF_LINK_HLEN + PBUF_LINK_ENCAPSULATION_HLEN)) {
|
||||
/* p is not big enough to contain link headers
|
||||
* allocate a new one and copy p into it
|
||||
*/
|
||||
@@ -176,7 +176,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
|
||||
/* copy the ip header */
|
||||
MEMCPY(r->payload, iphdr_in, hlen);
|
||||
/* switch r->payload back to icmp header (cannot fail) */
|
||||
if (pbuf_header(r, (s16_t)-hlen)) {
|
||||
if (pbuf_remove_header(r, hlen)) {
|
||||
LWIP_ASSERT("icmp_input: moving r->payload to icmp header failed\n", 0);
|
||||
pbuf_free(r);
|
||||
goto icmperr;
|
||||
@@ -193,7 +193,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
|
||||
p = r;
|
||||
} else {
|
||||
/* restore p->payload to point to icmp header (cannot fail) */
|
||||
if (pbuf_header(p, (s16_t)-(s16_t)(hlen + PBUF_LINK_HLEN + PBUF_LINK_ENCAPSULATION_HLEN))) {
|
||||
if (pbuf_remove_header(p, hlen + PBUF_LINK_HLEN + PBUF_LINK_ENCAPSULATION_HLEN)) {
|
||||
LWIP_ASSERT("icmp_input: restoring original p->payload failed\n", 0);
|
||||
goto icmperr;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
|
||||
/* We generate an answer by switching the dest and src ip addresses,
|
||||
* setting the icmp type to ECHO_RESPONSE and updating the checksum. */
|
||||
iecho = (struct icmp_echo_hdr *)p->payload;
|
||||
if (pbuf_header(p, (s16_t)hlen)) {
|
||||
if (pbuf_add_header(p, hlen)) {
|
||||
LWIP_DEBUGF(ICMP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("Can't move over header in packet"));
|
||||
} else {
|
||||
err_t ret;
|
||||
|
||||
@@ -674,7 +674,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
|
||||
if (raw_input(p, inp) == 0)
|
||||
#endif /* LWIP_RAW */
|
||||
{
|
||||
pbuf_header(p, (s16_t)-(s16_t)iphdr_hlen); /* Move to payload, no check necessary. */
|
||||
pbuf_remove_header(p, iphdr_hlen); /* Move to payload, no check necessary. */
|
||||
|
||||
switch (IPH_PROTO(iphdr)) {
|
||||
#if LWIP_UDP
|
||||
@@ -847,7 +847,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d
|
||||
optlen_aligned = (u16_t)((optlen + 3) & ~3);
|
||||
ip_hlen = (u16_t)(ip_hlen + optlen_aligned);
|
||||
/* First write in the IP options */
|
||||
if (pbuf_header(p, (s16_t)optlen_aligned)) {
|
||||
if (pbuf_add_header(p, optlen_aligned)) {
|
||||
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_output_if_opt: not enough room for IP options in pbuf\n"));
|
||||
IP_STATS_INC(ip.err);
|
||||
MIB2_STATS_INC(mib2.ipoutdiscards);
|
||||
@@ -866,7 +866,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d
|
||||
}
|
||||
#endif /* IP_OPTIONS_SEND */
|
||||
/* generate IP header */
|
||||
if (pbuf_header(p, IP_HLEN)) {
|
||||
if (pbuf_add_header(p, IP_HLEN)) {
|
||||
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_output: not enough room for IP header in pbuf\n"));
|
||||
|
||||
IP_STATS_INC(ip.err);
|
||||
|
||||
@@ -651,7 +651,7 @@ ip4_reass(struct pbuf *p)
|
||||
iprh = (struct ip_reass_helper*)r->payload;
|
||||
|
||||
/* hide the ip header for every succeeding fragment */
|
||||
pbuf_header(r, -IP_HLEN);
|
||||
pbuf_remove_header(r, IP_HLEN);
|
||||
pbuf_cat(p, r);
|
||||
r = iprh->next_pbuf;
|
||||
}
|
||||
@@ -779,7 +779,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
|
||||
(rambuf->len == rambuf->tot_len) && (rambuf->next == NULL));
|
||||
poff += pbuf_copy_partial(p, rambuf->payload, fragsize, poff);
|
||||
/* make room for the IP header */
|
||||
if (pbuf_header(rambuf, IP_HLEN)) {
|
||||
if (pbuf_add_header(rambuf, IP_HLEN)) {
|
||||
pbuf_free(rambuf);
|
||||
goto memerr;
|
||||
}
|
||||
|
||||
@@ -695,7 +695,7 @@ netif_found:
|
||||
hlen = hlen_tot = IP6_HLEN;
|
||||
|
||||
/* Move to payload. */
|
||||
pbuf_header(p, -IP6_HLEN);
|
||||
pbuf_remove_header(p, IP6_HLEN);
|
||||
|
||||
/* Process known option extension headers, if present. */
|
||||
while (nexth != IP6_NEXTH_NONE)
|
||||
@@ -722,7 +722,7 @@ netif_found:
|
||||
nexth = *((u8_t *)p->payload);
|
||||
|
||||
/* Skip over this header. */
|
||||
pbuf_header(p, (s16_t)-(s16_t)hlen);
|
||||
pbuf_remove_header(p, hlen);
|
||||
break;
|
||||
case IP6_NEXTH_DESTOPTS:
|
||||
LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: packet with Destination options header\n"));
|
||||
@@ -746,7 +746,7 @@ netif_found:
|
||||
nexth = *((u8_t *)p->payload);
|
||||
|
||||
/* Skip over this header. */
|
||||
pbuf_header(p, (s16_t)-(s16_t)hlen);
|
||||
pbuf_remove_header(p, hlen);
|
||||
break;
|
||||
case IP6_NEXTH_ROUTING:
|
||||
LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: packet with Routing header\n"));
|
||||
@@ -770,7 +770,7 @@ netif_found:
|
||||
/* Skip over this header. */
|
||||
hlen_tot = (u16_t)(hlen_tot + hlen);
|
||||
|
||||
pbuf_header(p, (s16_t)-(s16_t)hlen);
|
||||
pbuf_remove_header(p, hlen);
|
||||
break;
|
||||
|
||||
case IP6_NEXTH_FRAGMENT:
|
||||
@@ -804,7 +804,7 @@ netif_found:
|
||||
if ((frag_hdr->_fragment_offset &
|
||||
PP_HTONS(IP6_FRAG_OFFSET_MASK | IP6_FRAG_MORE_FLAG)) == 0) {
|
||||
/* This is a 1-fragment packet. Skip this header and continue. */
|
||||
pbuf_header(p, (s16_t)-(s16_t)hlen);
|
||||
pbuf_remove_header(p, hlen);
|
||||
} else {
|
||||
#if LWIP_IPV6_REASS
|
||||
|
||||
@@ -821,7 +821,7 @@ netif_found:
|
||||
ip6hdr = (struct ip6_hdr *)p->payload;
|
||||
nexth = IP6H_NEXTH(ip6hdr);
|
||||
hlen = hlen_tot = IP6_HLEN;
|
||||
pbuf_header(p, -IP6_HLEN);
|
||||
pbuf_remove_header(p, IP6_HLEN);
|
||||
|
||||
#else /* LWIP_IPV6_REASS */
|
||||
/* free (drop) packet pbufs */
|
||||
@@ -863,7 +863,7 @@ options_done:
|
||||
if (raw_input(p, inp) == 0)
|
||||
{
|
||||
/* Point to payload. */
|
||||
pbuf_header(p, (s16_t)-(s16_t)hlen_tot);
|
||||
pbuf_remove_header(p, hlen_tot);
|
||||
#else /* LWIP_RAW */
|
||||
{
|
||||
#endif /* LWIP_RAW */
|
||||
@@ -996,7 +996,7 @@ ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
|
||||
#endif /* LWIP_IPV6_SCOPES */
|
||||
|
||||
/* generate IPv6 header */
|
||||
if (pbuf_header(p, IP6_HLEN)) {
|
||||
if (pbuf_add_header(p, IP6_HLEN)) {
|
||||
LWIP_DEBUGF(IP6_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip6_output: not enough room for IPv6 header in pbuf\n"));
|
||||
IP6_STATS_INC(ip6.err);
|
||||
return ERR_BUF;
|
||||
@@ -1204,7 +1204,7 @@ ip6_options_add_hbh_ra(struct pbuf *p, u8_t nexth, u8_t value)
|
||||
struct ip6_hbh_hdr *hbh_hdr;
|
||||
|
||||
/* Move pointer to make room for hop-by-hop options header. */
|
||||
if (pbuf_header(p, sizeof(struct ip6_hbh_hdr))) {
|
||||
if (pbuf_add_header(p, sizeof(struct ip6_hbh_hdr))) {
|
||||
LWIP_DEBUGF(IP6_DEBUG, ("ip6_options: no space for options header\n"));
|
||||
IP6_STATS_INC(ip6.err);
|
||||
return ERR_BUF;
|
||||
|
||||
@@ -562,11 +562,11 @@ ip6_reass(struct pbuf *p)
|
||||
iprh_tmp = (struct ip6_reass_helper*)next_pbuf->payload;
|
||||
|
||||
/* hide the fragment header for every succeeding fragment */
|
||||
pbuf_header(next_pbuf, -IP6_FRAG_HLEN);
|
||||
pbuf_remove_header(next_pbuf, IP6_FRAG_HLEN);
|
||||
#if IPV6_FRAG_COPYHEADER
|
||||
if (IPV6_FRAG_REQROOM > 0) {
|
||||
/* hide the extra bytes borrowed from ip6_hdr for struct ip6_reass_helper */
|
||||
u8_t hdrerr = pbuf_header(next_pbuf, -(s16_t)(IPV6_FRAG_REQROOM));
|
||||
u8_t hdrerr = pbuf_remove_header(next_pbuf, IPV6_FRAG_REQROOM);
|
||||
LWIP_UNUSED_ARG(hdrerr); /* in case of LWIP_NOASSERT */
|
||||
LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == 0);
|
||||
}
|
||||
@@ -591,7 +591,7 @@ ip6_reass(struct pbuf *p)
|
||||
* header placed before the fragment header. */
|
||||
MEMCPY(p->payload, ipr->orig_hdr, IPV6_FRAG_REQROOM);
|
||||
/* get back room for struct ip6_reass_helper (only required if sizeof(void*) > 4) */
|
||||
hdrerr = pbuf_header(p, -(s16_t)(IPV6_FRAG_REQROOM));
|
||||
hdrerr = pbuf_remove_header(p, IPV6_FRAG_REQROOM);
|
||||
LWIP_UNUSED_ARG(hdrerr); /* in case of LWIP_NOASSERT */
|
||||
LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == 0);
|
||||
}
|
||||
@@ -760,7 +760,7 @@ ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest)
|
||||
(rambuf->len == rambuf->tot_len) && (rambuf->next == NULL));
|
||||
poff += pbuf_copy_partial(p, (u8_t*)rambuf->payload + IP6_FRAG_HLEN, cop, poff);
|
||||
/* make room for the IP header */
|
||||
if (pbuf_header(rambuf, IP6_HLEN)) {
|
||||
if (pbuf_add_header(rambuf, IP6_HLEN)) {
|
||||
pbuf_free(rambuf);
|
||||
IP6_FRAG_STATS_INC(ip6_frag.memerr);
|
||||
return ERR_MEM;
|
||||
|
||||
@@ -561,7 +561,7 @@ mld6_send(struct netif *netif, struct mld_group *group, u8_t type)
|
||||
}
|
||||
|
||||
/* Move to make room for Hop-by-hop options header. */
|
||||
if (pbuf_header(p, -IP6_HBH_HLEN)) {
|
||||
if (pbuf_remove_header(p, IP6_HBH_HLEN)) {
|
||||
pbuf_free(p);
|
||||
MLD6_STATS_INC(mld6.lenerr);
|
||||
return;
|
||||
|
||||
@@ -414,7 +414,7 @@ raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
||||
{
|
||||
err_t err;
|
||||
struct pbuf *q; /* q will be sent down the stack */
|
||||
s16_t header_size;
|
||||
u16_t header_size;
|
||||
u8_t ttl;
|
||||
|
||||
if ((pcb == NULL) || (dst_ip == NULL) || (netif == NULL) || (src_ip == NULL) ||
|
||||
@@ -451,7 +451,7 @@ raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
||||
return ERR_MEM;
|
||||
}
|
||||
/* not enough space to add an IP header to first pbuf in given p chain? */
|
||||
if (pbuf_header(p, header_size)) {
|
||||
if (pbuf_add_header(p, header_size)) {
|
||||
/* allocate header in new pbuf */
|
||||
q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM);
|
||||
/* new header pbuf could not be allocated? */
|
||||
@@ -468,7 +468,7 @@ raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
||||
} else {
|
||||
/* first pbuf q equals given pbuf */
|
||||
q = p;
|
||||
if (pbuf_header(q, (s16_t)-header_size)) {
|
||||
if (pbuf_remove_header(q, header_size)) {
|
||||
LWIP_ASSERT("Can't restore header we just removed!", 0);
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
||||
if (p->len >= hdrlen_bytes) {
|
||||
/* all options are in the first pbuf */
|
||||
tcphdr_opt1len = tcphdr_optlen;
|
||||
pbuf_header(p, (s16_t)-(s16_t)hdrlen_bytes); /* cannot fail */
|
||||
pbuf_remove_header(p, hdrlen_bytes); /* cannot fail */
|
||||
} else {
|
||||
u16_t opt2len;
|
||||
/* TCP header fits into first pbuf, options don't - data is in the next pbuf */
|
||||
@@ -186,7 +186,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
||||
LWIP_ASSERT("p->next != NULL", p->next != NULL);
|
||||
|
||||
/* advance over the TCP header (cannot fail) */
|
||||
pbuf_header(p, -TCP_HLEN);
|
||||
pbuf_remove_header(p, TCP_HLEN);
|
||||
|
||||
/* determine how long the first and second parts of the options are */
|
||||
tcphdr_opt1len = p->len;
|
||||
@@ -194,7 +194,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
||||
|
||||
/* options continue in the next pbuf: set p to zero length and hide the
|
||||
options in the next pbuf (adjusting p->tot_len) */
|
||||
pbuf_header(p, (s16_t)-(s16_t)tcphdr_opt1len);
|
||||
pbuf_remove_header(p, tcphdr_opt1len);
|
||||
|
||||
/* check that the options fit in the second pbuf */
|
||||
if (opt2len > p->next->len) {
|
||||
@@ -209,7 +209,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
||||
|
||||
/* advance p->next to point after the options, and manually
|
||||
adjust p->tot_len to keep it consistent with the changed p->next */
|
||||
pbuf_header(p->next, (s16_t)-(s16_t)opt2len);
|
||||
pbuf_remove_header(p->next, opt2len);
|
||||
p->tot_len = (u16_t)(p->tot_len - opt2len);
|
||||
|
||||
LWIP_ASSERT("p->len == 0", p->len == 0);
|
||||
|
||||
@@ -210,7 +210,7 @@ tcp_create_segment(struct tcp_pcb *pcb, struct pbuf *p, u8_t flags, u32_t seqno,
|
||||
#endif /* TCP_CHECKSUM_ON_COPY */
|
||||
|
||||
/* build TCP header */
|
||||
if (pbuf_header(p, TCP_HLEN)) {
|
||||
if (pbuf_add_header(p, TCP_HLEN)) {
|
||||
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_create_segment: no room for TCP header in pbuf.\n"));
|
||||
TCP_STATS_INC(tcp.err);
|
||||
tcp_seg_free(seg);
|
||||
|
||||
@@ -342,7 +342,7 @@ udp_input(struct pbuf *p, struct netif *inp)
|
||||
}
|
||||
}
|
||||
#endif /* CHECKSUM_CHECK_UDP */
|
||||
if (pbuf_header(p, -UDP_HLEN)) {
|
||||
if (pbuf_remove_header(p, UDP_HLEN)) {
|
||||
/* Can we cope with this failing? Just assert for now */
|
||||
LWIP_ASSERT("pbuf_header failed\n", 0);
|
||||
UDP_STATS_INC(udp.drop);
|
||||
@@ -712,7 +712,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
|
||||
return ERR_MEM;
|
||||
}
|
||||
/* not enough space to add an UDP header to first pbuf in given p chain? */
|
||||
if (pbuf_header(p, UDP_HLEN)) {
|
||||
if (pbuf_add_header(p, UDP_HLEN)) {
|
||||
/* allocate header in a separate new pbuf */
|
||||
q = pbuf_alloc(PBUF_IP, UDP_HLEN, PBUF_RAM);
|
||||
/* new header pbuf could not be allocated? */
|
||||
|
||||
Reference in New Issue
Block a user