The TCP window scaling index rcv_wscale
(f.e. while sending SYN or SYN-ACK) is calculated inside Linux kernel based on socket's receive buffer in function tcp_select_initial_window()
:
/* If no clamp set the clamp to the max possible scaled window */
if (*window_clamp == 0)
(*window_clamp) = (65535 << 14);
space = min(*window_clamp, space);
/* Quantize space offering to a multiple of mss if possible. */
if (space > mss)
space = (space / mss) * mss;
//...
(*rcv_wscale) = 0;
if (wscale_ok) {
/* Set window scaling on max possible window
* See RFC1323 for an explanation of the limit to 14
*/
space = max_t(u32, space, sysctl_tcp_rmem[2]);
space = max_t(u32, space, sysctl_rmem_max);
space = min_t(u32, space, *window_clamp);
while (space > 65535 && (*rcv_wscale) < 14) {
space >>= 1;
(*rcv_wscale)++;
}
}
Here space
is taken from the tcp_full_space()
based on sk_rcvbuf
.
Knowing that you can affect this calculation via changing size of receive buffer:
int buflen = 12345;
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &buflen, sizeof int) < 0)
perror("setsockopt():");
//...
This can give you zero scaling (WS=0
or wscale 0
).
P.S. keep in mind that at server side it should be done on listening socket, because you can't affect it after TCP-handshake.