TCP receiving Window -- confirm Window Scaling

Source: Internet
Author: User

TCP receiving Window -- confirm Window Scaling
1. Determination of rcv_scale

The cache configuration has a great relationship with the window scale value when the last three handshakes are interacted. The window scale value is determined by the tcp option when the three handshakes are performed.

1.1 client sends syn

During the three-way handshake, the scale Size is determined based on the configured cache size. When the syn Packet and syn + ack packets are sent, the tcp_connect_init function is called when the syn packet is created, in this function, the tcp_select_initial_window function assigns a value to rcv_wscale.

 
 
  1. Void tcp_select_initial_window (int _ space, _ u32 mss,
  2. _ U32 * rcv_wnd, _ u32 * window_clamp,
  3. Int wscale_ OK, _ u8 * rcv_wscale,
  4. _ U32 init_rcv_wnd)
  5. {
  6. Unsigned int space = (_ space <0? 0: _ space );

  7. /* If no clamp set the clamp to the max possible scaled window */
  8. If (* window_clamp = 0)
  9. (* Window_clamp) = (65535 <14 );
  10. Space = min (* window_clamp, space );

  11. /* Quantize space offering to a multiple of mss if possible .*/
  12. If (space> mss)
  13. Space = (space/mss) * mss;

  14. If (sysctl_tcp_workaround_signed_windows)
  15. (* Rcv_wnd) = min (space, MAX_TCP_WINDOW );
  16. Else
  17. (* Rcv_wnd) = space;
  18. (* Rcv_wscale) = 0;
  19. If (wscale_ OK) {/* Here, wscale_ OK corresponds to the sysctl_tcp_window_scaling parameter. The default Kernel configuration of this parameter is 1, indicating that scale is enabled */
  20. Space = max_t (u32, sysctl_tcp_rmem [2], sysctl_rmem_max );
  21. Space = min_t (u32, space, * window_clamp );
  22. While (space> 65535 & (* rcv_wscale) <14) {/* if the available space is greater than the maximum value that can be expressed by win and wsacle is less than 14, add 1 to rcv_wscale, narrow down space. */
  23. Space >>=1;
  24. (* Rcv_wscale) ++;
  25. }
  26. }

  27. If (mss> (1 <* rcv_wscale )){
  28. If (! Init_rcv_wnd)/* Use default unless specified otherwise */
  29. Init_rcv_wnd = tcp_default_init_rwnd (mss );
  30. * Rcv_wnd = min (* rcv_wnd, init_rcv_wnd * mss );
  31. }

  32. /* Set the clamp no higher than max representable value */
  33. (* Window_clamp) = min (65535U <(* rcv_wscale), * window_clamp );
  34. }



1.2 configure rcv_wscale for syn_ack packets

After receiving the syn packet, the following figure shows the rcv_scale setting process for sending the syn + ack packet. It also calls the tcp_select_initial_window function for initialization.

 
 
  1. Static unsigned int tcp_synack_options (struct sock * sk,
  2. Struct request_sock * req,
  3. Unsigned int mss, struct sk_buff * skb,
  4. Struct tcp_out_options * opts,
  5. Const struct tcp_md5sig_key * md5,
  6. Struct tcp_fastopen_cookie * foc)
  7. {
  8. Struct inet_request_sock * ireq = inet_rsk (req );
  9. Unsigned int remaining = MAX_TCP_OPTION_SPACE;

  10. # Ifdef CONFIG_TCP_MD5SIG
  11. If (md5 ){
  12. Opts-> options | = OPTION_MD5;
  13. Remaining-= TCPOLEN_MD5SIG_ALIGNED;
  14. Ireq-> tstamp_ OK & =! Ireq-> sack_ OK;
  15. }
  16. # Endif

  17. /* We always send an MSS option .*/
  18. Opts-> mss = mss;
  19. Remaining-= TCPOLEN_MSS_ALIGNED;
  20. If (likely (ireq-> wscale_ OK) {// set the tcp option Information wscale
  21. Opts-> ws = ireq-> rcv_wscale;
  22. Opts-> options | = OPTION_WSCALE;
  23. Remaining-= TCPOLEN_WSCALE_ALIGNED;
  24. }
  25. If (likely (ireq-> tstamp_ OK )){
  26. Opts-> options | = OPTION_TS;
  27. Opts-> tsval = tcp_skb_timestamp (skb );
  28. Opts-> tsecr = req-> ts_recent;
  29. Remaining-= TCPOLEN_TSTAMP_ALIGNED;
  30. }
  31. If (likely (ireq-> sack_ OK )){
  32. Opts-> options | = OPTION_SACK_ADVERTISE;
  33. If (unlikely (! Ireq-> tstamp_ OK ))
  34. Remaining-= TCPOLEN_SACKPERM_ALIGNED;
  35. }
  36. If (foc! = NULL & foc-> len> = 0 ){
  37. U32 need = foc-> len;

  38. Need + = foc-> exp? TCPOLEN_EXP_FASTOPEN_BASE:
  39. TCPOLEN_FASTOPEN_BASE;
  40. Need = (need + 3 )&~ 3U;/* Align to 32 bits */
  41. If (remaining> = need ){
  42. Opts-> options | = OPTION_FAST_OPEN_COOKIE;
  43. Opts-> fastopen_cookie = foc;
  44. Remaining-= need;
  45. }
  46. }
  47. Return MAX_TCP_OPTION_SPACE-remaining;
  48. }
1.3 resolution scale options

When receiving a scale datagram with the tcp option, the process is as follows, only for syn packets:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.