From 8a7c892e24bb268b422d49ae529d44707cd3296c Mon Sep 17 00:00:00 2001 From: Jovi Hsu Date: Tue, 16 Nov 2021 09:09:22 +0800 Subject: [PATCH] fix: The tcp zero window was never sent when it full of small packets Signed-off-by: Jovi Hsu --- src/ofp_tcp_output.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ofp_tcp_output.c b/src/ofp_tcp_output.c index 0fb2b812..18e57c44 100644 --- a/src/ofp_tcp_output.c +++ b/src/ofp_tcp_output.c @@ -1014,6 +1014,20 @@ ofp_tcp_output(struct tcpcb *tp) th->th_off = (sizeof (struct ofp_tcphdr) + optlen) >> 2; } th->th_flags = flags; + + /* + * Make sure to send the "real" so->so_rcv containing space. + * Unlike the FreeBSD stack, + * we shrink the receive window packet-by-packet, not byte-by-byte. + * So we cannot use (long)(tp->rcv_adv - tp->rcv_nxt)) to calculate the size of the window. + * Also, since recwin varies packet-by-packet, + * we don't need to care about silly window syndrome, + * since it always has a minimum delta of global_param->pkt_pool.buffer_size. + */ + /* Actually it should be recwin = recwin * tp->t_maxseg / global_param->pkt_pool.buffer_size + * But whatever. Just reduce the calculation here + */ +#if 0 /* * Calculate receive window. Don't shrink window, * but avoid silly window syndrome. @@ -1024,6 +1038,7 @@ ofp_tcp_output(struct tcpcb *tp) if (SEQ_GT(tp->rcv_adv, tp->rcv_nxt) && recwin < (long)(tp->rcv_adv - tp->rcv_nxt)) recwin = (long)(tp->rcv_adv - tp->rcv_nxt); +#endif if (recwin > (long)OFP_TCP_MAXWIN << tp->rcv_scale) recwin = (long)OFP_TCP_MAXWIN << tp->rcv_scale;