TCP窗口比例选项非零的原因 [英] The reason of non-zero TCP window scale option
问题描述
我读了一些有关 TCP窗口缩放和
I read some stuff about TCP window scaling and BDP(not quite clear), and I can't figure out what exactly cause sender's TCP realization to set non-zero WS and could the user-mode client program affect it somehow? I think that logically it cannot be based on some data transferring because it happens on SYN-SYN+ACK TCP stage.
有人可以从编程的角度解释一下,用户模式客户端代码如何影响TCP窗口缩放选项(例如,在connect()
调用之前)? TCP堆栈如何知道何时将WS设置为非零?
Can someone explain from programming point of view, how can user-mode client code affect on TCP window scale option (e.g. before connect()
call)? And how TCP stack knows when to set WS to non-zero?
很抱歉,如果很明显.
推荐答案
TCP窗口缩放索引rcv_wscale
(发送 SYN 或 SYN-ACK 时的fe)是在Linux内核中基于套接字 tcp_select_initial_window()
:
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)++;
}
}
此处space
是根据sk_rcvbuf
从tcp_full_space()
中提取的.
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():");
//...
这可以为您提供零缩放( WS=0
或 wscale 0
).
This can give you zero scaling (WS=0
or wscale 0
).
P.S.请记住,在服务器端,应该在侦听套接字上完成此操作,因为在TCP握手之后您不能影响它.
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.
这篇关于TCP窗口比例选项非零的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!