From 8fe9e007c924f7a518ca250927c127a6b9aaad07 Mon Sep 17 00:00:00 2001 From: kieranm Date: Thu, 24 Oct 2002 10:57:44 +0000 Subject: [PATCH] Fixed congestion window bug where the pcb->cwnd variable overflowed when increased. --- src/core/tcp_in.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index a21a9516..573f2c9e 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -641,7 +641,7 @@ tcp_receive(struct tcp_pcb *pcb) } else { /* Inflate the congestion window, but not if it means that the value overflows. */ - if(pcb->cwnd + pcb->mss > pcb->cwnd) { + if((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) { pcb->cwnd += pcb->mss; } @@ -677,15 +677,16 @@ tcp_receive(struct tcp_pcb *pcb) ssthresh). */ if(pcb->state >= ESTABLISHED) { if(pcb->cwnd < pcb->ssthresh) { - if(pcb->cwnd + pcb->mss > pcb->cwnd) { + if((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) { pcb->cwnd += pcb->mss; } DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: slow start cwnd %u\n", pcb->cwnd)); } else { - if(pcb->cwnd + pcb->mss * pcb->mss / pcb->cwnd > pcb->cwnd) { - pcb->cwnd += pcb->mss * pcb->mss / pcb->cwnd; + u16_t new_cwnd = (pcb->cwnd + pcb->mss * pcb->mss / pcb->cwnd); + if(new_cwnd > pcb->cwnd) { + pcb->cwnd = new_cwnd; } - DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: congestion avoidance cwnd %u\n", pcb->cwnd)); + DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: congestion avoidance cwnd %u\n", pcb->cwnd)); } } DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: ACK for %lu, unacked->seqno %lu:%lu\n",