mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-26 09:35:23 +00:00
Fixed bug #29080: Correctly handle remote side overrunning our rcv_wnd in ooseq case.
This commit is contained in:
parent
d861daeb4e
commit
cf0b831971
@ -169,6 +169,10 @@ HISTORY
|
|||||||
|
|
||||||
++ Bugfixes:
|
++ Bugfixes:
|
||||||
|
|
||||||
|
2010-03-25: Simon Goldschmidt
|
||||||
|
* tcp_in.c, test_tcp_oos.c: Fixed bug #29080: Correctly handle remote side
|
||||||
|
overrunning our rcv_wnd in ooseq case.
|
||||||
|
|
||||||
2010-03-22: Simon Goldschmidt
|
2010-03-22: Simon Goldschmidt
|
||||||
* tcp.c: tcp_listen() did not copy the pcb's prio.
|
* tcp.c: tcp_listen() did not copy the pcb's prio.
|
||||||
|
|
||||||
|
@ -1402,6 +1402,24 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
next->len = (u16_t)(seqno - next->tcphdr->seqno);
|
next->len = (u16_t)(seqno - next->tcphdr->seqno);
|
||||||
pbuf_realloc(next->p, next->len);
|
pbuf_realloc(next->p, next->len);
|
||||||
}
|
}
|
||||||
|
/* check if the remote side overruns our receive window */
|
||||||
|
if ((u32_t)tcplen + seqno > pcb->rcv_nxt + (u32_t)pcb->rcv_wnd) {
|
||||||
|
LWIP_DEBUGF(TCP_INPUT_DEBUG,
|
||||||
|
("tcp_receive: other end overran receive window"
|
||||||
|
"seqno %"U32_F" len %"U16_F" right edge %"U32_F"\n",
|
||||||
|
seqno, tcplen, pcb->rcv_nxt + pcb->rcv_wnd));
|
||||||
|
if (TCPH_FLAGS(next->next->tcphdr) & TCP_FIN) {
|
||||||
|
/* Must remove the FIN from the header as we're trimming
|
||||||
|
* that byte of sequence-space from the packet */
|
||||||
|
TCPH_FLAGS_SET(next->next->tcphdr, TCPH_FLAGS(next->next->tcphdr) &~ TCP_FIN);
|
||||||
|
}
|
||||||
|
/* Adjust length of segment to fit in the window. */
|
||||||
|
next->next->len = pcb->rcv_nxt + pcb->rcv_wnd - seqno;
|
||||||
|
pbuf_realloc(next->next->p, next->next->len);
|
||||||
|
tcplen = TCP_TCPLEN(next->next);
|
||||||
|
LWIP_ASSERT("tcp_receive: segment not trimmed correctly to rcv_wnd\n",
|
||||||
|
(seqno + tcplen) == (pcb->rcv_nxt + pcb->rcv_wnd));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ tcp_oos_seg_seqno(struct tcp_pcb* pcb, int seg_index)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the tcplen of a segment (by index) on the ooseq list
|
/** Get the tcplen (datalen + SYN/FIN) of a segment (by index) on the ooseq list
|
||||||
*
|
*
|
||||||
* @param pcb the pcb to check for ooseq segments
|
* @param pcb the pcb to check for ooseq segments
|
||||||
* @param seg_index index of the segment on the ooseq list
|
* @param seg_index index of the segment on the ooseq list
|
||||||
@ -84,6 +84,25 @@ tcp_oos_seg_tcplen(struct tcp_pcb* pcb, int seg_index)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the tcplen (datalen + SYN/FIN) of all segments on the ooseq list
|
||||||
|
*
|
||||||
|
* @param pcb the pcb to check for ooseq segments
|
||||||
|
* @return tcplen of all segment
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
tcp_oos_tcplen(struct tcp_pcb* pcb)
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
struct tcp_seg* seg = pcb->ooseq;
|
||||||
|
|
||||||
|
/* then check the actual segment */
|
||||||
|
while(seg != NULL) {
|
||||||
|
len += TCP_TCPLEN(seg);
|
||||||
|
seg = seg->next;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
/* Setup/teardown functions */
|
/* Setup/teardown functions */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -415,6 +434,99 @@ START_TEST(test_tcp_recv_ooseq_FIN_INSEQ)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
static char data_full_wnd[TCP_WND];
|
||||||
|
|
||||||
|
/** create multiple segments and pass them to tcp_input with the first segment missing
|
||||||
|
* to simulate overruning the rxwin with ooseq queueing enabled */
|
||||||
|
START_TEST(test_tcp_recv_ooseq_overrun_rxwin)
|
||||||
|
{
|
||||||
|
int i, k;
|
||||||
|
struct test_tcp_counters counters;
|
||||||
|
struct tcp_pcb* pcb;
|
||||||
|
struct pbuf *pinseq, *p_ovr;
|
||||||
|
ip_addr_t remote_ip, local_ip;
|
||||||
|
u16_t remote_port = 0x100, local_port = 0x101;
|
||||||
|
struct netif netif;
|
||||||
|
int datalen = 0;
|
||||||
|
int datalen2;
|
||||||
|
LWIP_UNUSED_ARG(_i);
|
||||||
|
|
||||||
|
for(i = 0; i < sizeof(data_full_wnd); i++) {
|
||||||
|
data_full_wnd[i] = (char)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* initialize local vars */
|
||||||
|
memset(&netif, 0, sizeof(netif));
|
||||||
|
IP4_ADDR(&local_ip, 192, 168, 1, 1);
|
||||||
|
IP4_ADDR(&remote_ip, 192, 168, 1, 2);
|
||||||
|
/* initialize counter struct */
|
||||||
|
memset(&counters, 0, sizeof(counters));
|
||||||
|
counters.expected_data_len = TCP_WND;
|
||||||
|
counters.expected_data = data_full_wnd;
|
||||||
|
|
||||||
|
/* create and initialize the pcb */
|
||||||
|
pcb = test_tcp_new_counters_pcb(&counters);
|
||||||
|
EXPECT_RET(pcb != NULL);
|
||||||
|
tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port);
|
||||||
|
pcb->rcv_nxt = 0x8000;
|
||||||
|
|
||||||
|
/* create segments */
|
||||||
|
/* pinseq is sent as last segment! */
|
||||||
|
pinseq = tcp_create_rx_segment(pcb, &data_full_wnd[0], TCP_MSS, 0, 0, TCP_ACK);
|
||||||
|
|
||||||
|
for(i = TCP_MSS, k = 0; i < TCP_WND; i += TCP_MSS, k++) {
|
||||||
|
int count, expected_datalen;
|
||||||
|
struct pbuf *p = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)],
|
||||||
|
TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
|
||||||
|
EXPECT(p != NULL);
|
||||||
|
/* pass the segment to tcp_input */
|
||||||
|
tcp_input(p, &netif);
|
||||||
|
/* check if counters are as expected */
|
||||||
|
EXPECT(counters.close_calls == 0);
|
||||||
|
EXPECT(counters.recv_calls == 0);
|
||||||
|
EXPECT(counters.recved_bytes == 0);
|
||||||
|
EXPECT(counters.err_calls == 0);
|
||||||
|
/* check ooseq queue */
|
||||||
|
count = tcp_oos_count(pcb);
|
||||||
|
EXPECT_OOSEQ(count == k+1);
|
||||||
|
datalen = tcp_oos_tcplen(pcb);
|
||||||
|
if (i + TCP_MSS < TCP_WND) {
|
||||||
|
expected_datalen = (k+1)*TCP_MSS;
|
||||||
|
} else {
|
||||||
|
expected_datalen = TCP_WND - TCP_MSS;
|
||||||
|
}
|
||||||
|
if (datalen != expected_datalen) {
|
||||||
|
EXPECT_OOSEQ(datalen == expected_datalen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pass in one more segment, cleary overrunning the rxwin */
|
||||||
|
p_ovr = tcp_create_rx_segment(pcb, &data_full_wnd[TCP_MSS*(k+1)], TCP_MSS, TCP_MSS*(k+1), 0, TCP_ACK);
|
||||||
|
EXPECT(p_ovr != NULL);
|
||||||
|
/* pass the segment to tcp_input */
|
||||||
|
tcp_input(p_ovr, &netif);
|
||||||
|
/* check if counters are as expected */
|
||||||
|
EXPECT(counters.close_calls == 0);
|
||||||
|
EXPECT(counters.recv_calls == 0);
|
||||||
|
EXPECT(counters.recved_bytes == 0);
|
||||||
|
EXPECT(counters.err_calls == 0);
|
||||||
|
/* check ooseq queue */
|
||||||
|
EXPECT_OOSEQ(tcp_oos_count(pcb) == k);
|
||||||
|
datalen2 = tcp_oos_tcplen(pcb);
|
||||||
|
EXPECT_OOSEQ(datalen == datalen2);
|
||||||
|
|
||||||
|
/* now pass inseq */
|
||||||
|
tcp_input(pinseq, &netif);
|
||||||
|
EXPECT(pcb->ooseq == NULL);
|
||||||
|
|
||||||
|
/* make sure the pcb is freed */
|
||||||
|
EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 1);
|
||||||
|
tcp_abort(pcb);
|
||||||
|
EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 0);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
/** Create the suite including all tests for this module */
|
/** Create the suite including all tests for this module */
|
||||||
Suite *
|
Suite *
|
||||||
tcp_oos_suite(void)
|
tcp_oos_suite(void)
|
||||||
@ -422,6 +534,7 @@ tcp_oos_suite(void)
|
|||||||
TFun tests[] = {
|
TFun tests[] = {
|
||||||
test_tcp_recv_ooseq_FIN_OOSEQ,
|
test_tcp_recv_ooseq_FIN_OOSEQ,
|
||||||
test_tcp_recv_ooseq_FIN_INSEQ,
|
test_tcp_recv_ooseq_FIN_INSEQ,
|
||||||
|
test_tcp_recv_ooseq_overrun_rxwin,
|
||||||
};
|
};
|
||||||
return create_suite("TCP_OOS", tests, sizeof(tests)/sizeof(TFun), tcp_oos_setup, tcp_oos_teardown);
|
return create_suite("TCP_OOS", tests, sizeof(tests)/sizeof(TFun), tcp_oos_setup, tcp_oos_teardown);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user