From: Wesley Atwell <[email protected]>

Refresh the live rwnd snapshot whenever TCP updates tp->rcv_wnd at the
normal write sites, including child setup, tcp_select_window(), and the
initial connect-time window selection.

This keeps the live sender-visible window paired with the scaling basis
that was actually advertised.

Signed-off-by: Wesley Atwell <[email protected]>
---
 net/ipv4/tcp_minisocks.c | 2 +-
 net/ipv4/tcp_output.c    | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index d350d794a959..1c02c9cd13fe 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -603,7 +603,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
        newtp->rx_opt.sack_ok = ireq->sack_ok;
        newtp->window_clamp = req->rsk_window_clamp;
        newtp->rcv_ssthresh = req->rsk_rcv_wnd;
-       newtp->rcv_wnd = req->rsk_rcv_wnd;
+       tcp_set_rcv_wnd(newtp, req->rsk_rcv_wnd);
        newtp->rcv_mwnd_seq = newtp->rcv_wup + req->rsk_rcv_wnd;
        newtp->rx_opt.wscale_ok = ireq->wscale_ok;
        if (newtp->rx_opt.wscale_ok) {
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 35c3b0ab5a0c..0b082726d7c4 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -291,7 +291,7 @@ static u16 tcp_select_window(struct sock *sk)
         */
        if (unlikely(inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM)) {
                tp->pred_flags = 0;
-               tp->rcv_wnd = 0;
+               tcp_set_rcv_wnd(tp, 0);
                tp->rcv_wup = tp->rcv_nxt;
                tcp_update_max_rcv_wnd_seq(tp);
                return 0;
@@ -315,7 +315,7 @@ static u16 tcp_select_window(struct sock *sk)
                }
        }
 
-       tp->rcv_wnd = new_win;
+       tcp_set_rcv_wnd(tp, new_win);
        tp->rcv_wup = tp->rcv_nxt;
        tcp_update_max_rcv_wnd_seq(tp);
 
@@ -4148,6 +4148,10 @@ static void tcp_connect_init(struct sock *sk)
                                  
READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling),
                                  &rcv_wscale,
                                  rcv_wnd);
+       /* tcp_select_initial_window() filled tp->rcv_wnd through its out-param,
+        * so snapshot the scaling_ratio we will use for that initial rwnd.
+        */
+       tcp_set_rcv_wnd(tp, tp->rcv_wnd);
 
        tp->rx_opt.rcv_wscale = rcv_wscale;
        tp->rcv_ssthresh = tp->rcv_wnd;
-- 
2.43.0


Reply via email to