TCP: simplify trimming left edge & use pbuf_remove_header() instead of pbuf_header()

This commit is contained in:
goldsimon 2017-08-21 22:34:44 +02:00
parent 22ee33951b
commit 1ed1cfe83a

View File

@ -1083,10 +1083,8 @@ tcp_receive(struct tcp_pcb *pcb)
#if TCP_QUEUE_OOSEQ #if TCP_QUEUE_OOSEQ
struct tcp_seg *prev, *cseg; struct tcp_seg *prev, *cseg;
#endif /* TCP_QUEUE_OOSEQ */ #endif /* TCP_QUEUE_OOSEQ */
s32_t off;
s16_t m; s16_t m;
u32_t right_wnd_edge; u32_t right_wnd_edge;
u16_t new_tot_len;
int found_dupack = 0; int found_dupack = 0;
#if TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS #if TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS
u32_t ooseq_blen; u32_t ooseq_blen;
@ -1381,32 +1379,23 @@ tcp_receive(struct tcp_pcb *pcb)
length.*/ length.*/
struct pbuf *p = inseg.p; struct pbuf *p = inseg.p;
off = pcb->rcv_nxt - seqno; u32_t off32 = pcb->rcv_nxt - seqno;
u16_t new_tot_len, off;
LWIP_ASSERT("inseg.p != NULL", inseg.p); LWIP_ASSERT("inseg.p != NULL", inseg.p);
LWIP_ASSERT("insane offset!", (off < 0x7fff)); LWIP_ASSERT("insane offset!", (off32 < 0xffff));
if (inseg.p->len < off) { off = (u16_t)off32;
LWIP_ASSERT("pbuf too short!", (((s32_t)inseg.p->tot_len) >= off)); LWIP_ASSERT("pbuf too short!", (((s32_t)inseg.p->tot_len) >= off));
new_tot_len = (u16_t)(inseg.p->tot_len - off); inseg.len -= off;
while (p->len < off) { new_tot_len = (u16_t)(inseg.p->tot_len - off);
off -= p->len; while (p->len < off) {
/* KJM following line changed (with addition of new_tot_len var) off -= p->len;
to fix bug #9076 /* all pbufs up to and including this one have len==0, so tot_len is equal */
inseg.p->tot_len -= p->len; */ p->tot_len = new_tot_len;
p->tot_len = new_tot_len; p->len = 0;
p->len = 0; p = p->next;
p = p->next;
}
if (pbuf_header(p, (s16_t)-off)) {
/* Do we need to cope with this failing? Assert for now */
LWIP_ASSERT("pbuf_header failed", 0);
}
} else {
if (pbuf_header(inseg.p, (s16_t)-off)) {
/* Do we need to cope with this failing? Assert for now */
LWIP_ASSERT("pbuf_header failed", 0);
}
} }
inseg.len -= (u16_t)(pcb->rcv_nxt - seqno); /* cannot fail... */
pbuf_remove_header(p, off);
inseg.tcphdr->seqno = seqno = pcb->rcv_nxt; inseg.tcphdr->seqno = seqno = pcb->rcv_nxt;
} }
else { else {