google / netstack

IPv4 and IPv6 userland network stack
Apache License 2.0
3.09k stars 279 forks source link

Is send window scale wrong? #12

Closed fanpei91 closed 6 years ago

fanpei91 commented 6 years ago

https://github.com/google/netstack/blob/26bc1beb19b61a85b86be893b58e91b96e5a029d/tcpip/transport/tcp/connect.go#L310

Is it should be written as the following?

if s.flagIsSet(flagSyn) && h.sndWndScale > 0 {
...
}

rfc1323: This option is sent only in a SYN segment (a segment with the SYN bit on)

iangudger commented 6 years ago

Hmm, looks wrong to me. @hbhasker, thoughts?

iangudger commented 6 years ago

For reference, this was added in https://github.com/google/netstack/commit/9527cbdc82c1bc0a7c3d64eb69df039119394185#diff-04661a3cf15a0f0b7871767d7208e024R273

hbhasker commented 6 years ago

This is correct. What this is doing is scaling the window if window scaling was enabled. This basically stores the send window based on the advertised window in the last ack of the TCP handshake.

See from rfc 1323.

The window field (SEG.WND) in the header of every incoming segment, with the exception of SYN segments, is left-shifted by Snd.Wind.Scale bits before updating SND.WND:

          SND.WND = SEG.WND << Snd.Wind.Scale

       (assuming the other conditions of RFC793 are met, and using
       the "C" notation "<<" for left-shift).
fanpei91 commented 6 years ago

Oh yes, you are right!