"net/mptcp/mptcp_output.c" line 771 of 1667
771 u32 __mptcp_select_window(struct sock *sk)
772 {
773 struct inet_connection_sock *icsk = inet_csk(sk);
774 struct tcp_sock *tp = tcp_sk(sk), *meta_tp = mptcp_meta_tp(tp);
775 struct sock *meta_sk = mptcp_meta_sk(sk);
776 int mss, free_space, full_space, window;
777
778 /* MSS for the peer's data. Previous versions used mss_clamp
779 * here. I don't know if the value based on our guesses
780 * of peer's MSS is better for the performance. It's more correct
781 * but may be worse for the performance because of rcv_mss
782 * fluctuations. --SAW 1998/11/1
783 */
784 mss = icsk->icsk_ack.rcv_mss;
785 free_space = tcp_space(meta_sk);
786 full_space = min_t(int, meta_tp->window_clamp,
787 tcp_full_space(meta_sk));
788
789 if (mss > full_space)
790 mss = full_space;
791
792 if (free_space < (full_space >> 1)) {
793 icsk->icsk_ack.quick = 0;
794
795 if (tcp_memory_pressure)
796 /* TODO this has to be adapted when we support different
797 * MSS's among the subflows.
798 */
799 meta_tp->rcv_ssthresh = min(meta_tp->rcv_ssthresh,
800 4U * meta_tp->advmss);
801
802 if (free_space < mss)
803 return 0;
804 }
805
806 if (free_space > meta_tp->rcv_ssthresh)
807 free_space = meta_tp->rcv_ssthresh;
808
809 /* Don't do rounding if we are using window scaling, since the
810 * scaled window will not line up with the MSS boundary anyway.
811 */
812 window = meta_tp->rcv_wnd;
813 if (tp->rx_opt.rcv_wscale) {
814 window = free_space;
815
816 /* Advertise enough space so that it won't get scaled away.
817 * Import case: prevent zero window announcement if
818 * 1<<rcv_wscale > mss.
819 */
820 if (((window >> tp->rx_opt.rcv_wscale) << tp->
821 rx_opt.rcv_wscale) != window)
822 window = (((window >> tp->rx_opt.rcv_wscale) + 1)
823 << tp->rx_opt.rcv_wscale);
824 } else {
825 /* Get the largest window that is a nice multiple of mss.
826 * Window clamp already applied above.
827 * If our current window offering is within 1 mss of the
828 * free space we just keep it. This prevents the divide
829 * and multiply from happening most of the time.
830 * We also don't do any window rounding when the free space
831 * is too small.
832 */
833 if (window <= free_space - mss || window > free_space)
834 window = (free_space / mss) * mss;
835 else if (mss == full_space &&
836 free_space > window + (full_space >> 1))
837 window = free_space;
838 }
839
840 return window;
841 }