Bug 82470 - FreeBSD advertises wrong window scale in some situations
Summary: FreeBSD advertises wrong window scale in some situations
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 5.4-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-net (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2005-06-21 09:30 UTC by Pieter de Boer
Modified: 2018-01-01 00:30 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pieter de Boer 2005-06-21 09:30:18 UTC
      Setting a recv buffer of (65535*2)+1 lets FreeBSD advertise a window of 65535<<2 (window scale 2, 256KB) in stead of 65535<<1 (window scale 1, 128KB). So FreeBSD is advertising a window bigger than the actual available receive space. When setting the buffer to 65535*2 exactly, the window scale option is set correctly.

Fix: 

Haven't had time to look into it yet, sorry.
How-To-Repeat:       sysctl net.inet.tcp.recvspace=131071

Then set up a connection from the FreeBSD system to something else. FreeBSD will advertise a windowsize of 256KB, although there's only 1 byte more than 128KB available.
Comment 1 Tilman Keskinoz freebsd_committer freebsd_triage 2005-06-29 13:18:53 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-net

over to Networking experts
Comment 2 Pieter de Boer 2005-07-24 14:39:15 UTC
The following patch seems to fix the problem:


diff -u netinet.orig/tcp_syncache.c netinet/tcp_syncache.c
--- netinet.orig/tcp_syncache.c	Sun Jul 24 15:26:14 2005
+++ netinet/tcp_syncache.c	Sun Jul 24 15:26:56 2005
@@ -966,7 +966,7 @@

  			/* Compute proper scaling value from buffer space */
  			while (wscale < TCP_MAX_WINSHIFT &&
-			    (TCP_MAXWIN << wscale) < so->so_rcv.sb_hiwat)
+			    (TCP_MAXWIN << (wscale + 1)) <= so->so_rcv.sb_hiwat)
  				wscale++;
  			sc->sc_request_r_scale = wscale;
  			sc->sc_requested_s_scale = to->to_requested_s_scale;
diff -u netinet.orig/tcp_usrreq.c netinet/tcp_usrreq.c
--- netinet.orig/tcp_usrreq.c	Sun Jul 24 15:26:14 2005
+++ netinet/tcp_usrreq.c	Sun Jul 24 15:26:47 2005
@@ -888,7 +888,7 @@

  	/* Compute window scaling to request.  */
  	while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
-	    (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
+	    (TCP_MAXWIN << (tp->request_r_scale + 1)) <= so->so_rcv.sb_hiwat)
  		tp->request_r_scale++;

  	soisconnecting(so);
@@ -950,7 +950,7 @@

  	/* Compute window scaling to request.  */
  	while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
-	    (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
+	    (TCP_MAXWIN << (tp->request_r_scale + 1)) <= so->so_rcv.sb_hiwat)
  		tp->request_r_scale++;

  	soisconnecting(so);
Comment 3 Robert Watson freebsd_committer freebsd_triage 2005-08-03 10:13:49 UTC
Responsible Changed
From-To: freebsd-net->silby

Chown to silby, who has recently been spending some quality time with TCP.
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2015-11-12 01:29:43 UTC
Reassign to the wild with permission of assignee.

To submitter: is this report still valid?
Comment 5 Eitan Adler freebsd_committer freebsd_triage 2018-01-01 00:30:16 UTC
Inspection of code appears to show that this problem has since been fixed. If I have mis-read the code please feel free to re-open.